skillfed

pydantic-to-typescript

Convert pydantic models to typescript interfaces

pydantic-to-typescript v2.0.0 863.7K downloads/30d#4,867 on PyPI432
Permissive license MIT DORMANT released

What it is and what it does

pydantic-to-typescript is a CLI tool that reads pydantic model definitions from a Python module and generates corresponding TypeScript interface definitions. It bridges the gap between Python and JavaScript type systems by allowing teams to maintain a single authoritative source of type definitions in Python, then automatically generate matching TypeScript interfaces for frontend consumption. The tool depends on pydantic for model introspection and json2ts for the actual TypeScript generation.

The package is designed for full-stack applications where Python backends serve APIs consumed by TypeScript/JavaScript frontends. Instead of manually keeping type definitions in sync across languages, you define your data models once in pydantic and run the tool to generate TypeScript interfaces that match exactly. The generated interfaces are marked as auto-generated to discourage manual edits, reinforcing the single-source-of-truth pattern.

Use it for:

  • Generate TypeScript types for a backend's request/response models to keep frontend and backend type definitions synchronized.
  • Exclude sensitive or internal pydantic models from TypeScript output using the --exclude flag when only a subset of models should be exposed.
  • Integrate into a build pipeline to regenerate TypeScript definitions whenever pydantic models change, ensuring frontend types never drift from backend reality.
  • Convert a Python module with multiple interdependent pydantic models into a single TypeScript definitions file for import across a frontend codebase.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Converts pydantic model definitions into TypeScript interface definitions via a CLI tool, enabling a single source of truth for type definitions across Python and JavaScript applications.

Yes, if you have a Python backend with pydantic models and a TypeScript frontend that needs to stay in sync. The package solves a real problem—type definition drift—with minimal overhead. Install friction is low and the MIT license is unrestricted. The main caveat is dormant maintenance (last release 630 days ago), so if you rely on cutting-edge pydantic features or need active support, evaluate whether the tool handles your specific model patterns before committing.

Install

pydantic-to-typescript on PyPI

pip

pip install pydantic-to-typescript

uv

uv add pydantic-to-typescript

poetry

poetry add pydantic-to-typescript

Installing pydantic-to-typescript

Before you install

Low friction install with a single runtime dependency (pydantic). Maintenance is dormant—last commit was 2024-11-22 and no release in 630 days—but the package is marked Production/Stable and carries 432 GitHub stars, suggesting it remains functional for its narrow use case.

License in practice

MIT license (permissive) places no restrictions on use, modification, or distribution in commercial or proprietary projects.

Quickstart

pip install pydantic-to-typescript

from pydantic import BaseModel

class User(BaseModel):
    name: str
    age: int

# Then run: pydantic2ts --module mymodule --output ./types.ts

Requires json2ts CLI utility (npm package json-schema-to-typescript) to be installed and accessible on the system PATH or specified via --json2ts-cmd flag.

Verify before relying

  • Whether the package handles complex pydantic features (validators, computed fields, discriminated unions) correctly in TypeScript output.
  • Performance characteristics when converting large numbers of models or deeply nested model hierarchies.
  • Compatibility with recent pydantic v2 field definitions and serialization modes beyond basic type mapping.

Package facts

License MIT (permissive)
Python support supports the current Python release (>=3.8)
Install friction low — pure-Python wheel
Runtime dependencies 1 — pydantic
Maintenance dormant — 630 days since the last release
Last repo commit
First released
Downloads 863,682/month — #4,867 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: pydantic_to_typescript-2.0.0-py3-none-any.whl

Keywords: annotations, interface, pydantic, typescript, validation

Development Status :: 5 - Production/StableLicense :: OSI Approved :: MIT LicenseProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9

Tags

pydantic to typescript conversiongenerate typescript from python modelspython typescript type syncpydantic typescript interface generatorcross-language type definitionspython javascript type bridge
type-generationcross-language-syncapi-tooling

More Software Development packages