Skip to main content

Convert pydantic models to typescript interfaces

Project description

pydantic-to-typescript

A simple CLI tool for converting pydantic models into typescript interfaces. Useful for any scenario in which python and javascript applications are interacting, since it allows you to have a single source of truth for type definitions.

This tool requires that you have the lovely json2ts CLI utility installed. Instructions can be found here: https://www.npmjs.com/package/json-schema-to-typescript

Installation

$ pip install pydantic-to-typescript

Command-line usage

Prop Description
--module name of the python module you would like to convert. All the pydantic models within it will be converted to typescript interfaces. Discoverable submodules will also be checked. Ex: 'pydantic2ts.examples.pydantic_models'
--output name of the file the typescript definitions should be written to. Ex: '/frontend/api-types.ts'
--json2ts-cmd optional, the command used to invoke json2ts. The default is 'json2ts'. Specify this if you have it installed in a strange location and need to provide the exact path (ex: /myproject/node_modules/bin/json2ts)

Example:

$ pydantic2ts --module pydantic2ts.examples.pydantic_models --output output.ts

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pydantic-to-typescript-1.0.2.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

pydantic_to_typescript-1.0.2-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file pydantic-to-typescript-1.0.2.tar.gz.

File metadata

  • Download URL: pydantic-to-typescript-1.0.2.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.7

File hashes

Hashes for pydantic-to-typescript-1.0.2.tar.gz
Algorithm Hash digest
SHA256 a0c78fe34dce1c3e5a21acb36a6619634d576c631845c7e6efdf82e4101595f2
MD5 cf0aa8f66fb361c4390a48680869eb3b
BLAKE2b-256 eb201e5eecea76f8a337c7a4766453e34d2fa1f5fae94d9d92949c047ddc790c

See more details on using hashes here.

File details

Details for the file pydantic_to_typescript-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: pydantic_to_typescript-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.7

File hashes

Hashes for pydantic_to_typescript-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 97cc44f1d827110a0f4ed58636ede2c213433ae20a25a20530ccb826d93d76d2
MD5 983d72ff6fc648e78720ce34e4f97ce2
BLAKE2b-256 2b7225621882b84b874492e6d194b2cc63f55ea9fccfdf6e1c386711c76c9e35

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page