Skip to main content
Build Status codecov pyup

pytypgen

Code generator that converts from Python types (implemented by dataclasses) to TypeScript interfaces

Dependencies

  • Python 3.7 (need dataclass)

Install

pip install pytypegen

Usage

from pytypgen.core import contracts_to_typescript, Contract

class Gender(Enum):
    male = 1
    female = 2


@dataclass
class Address(Contract):
    street: str


@dataclass
class Person(Contract):
    name: str
    gender: Gender
    birth_date: datetime.datetime
    addresses: Optional[List[Address]] = None

print(contracts_to_typescript(dataclasses=[Gender, Address, Person]))

Will generate the following TypeScript code:

export enum Gender {
  male = 'male',
  female = 'female'
}

export interface Address {
  street: string
}

export interface Person {
  name: string
  gender: Gender
  birth_date: string
  addresses?: Array<Address>|null
}

Development Setup

  • Run make setup. This will setup a pre-commit hook which creates README.rst file.

  • Run pip install -r dev-requirements.txt, preferably in a virtualenv.

Metadata

Release files for pytypegen 1.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytypegen 1.0.4
File Size Uploaded Provenance Actions
pytypegen-1.0.4.tar.gz 9.7 kB Without provenance Details for pytypegen-1.0.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pytypegen 1.0.4
File Interpreter ABI Platform Actions
pytypegen-1.0.4-py3-none-any.whl Python 3 none any Details for pytypegen-1.0.4-py3-none-any.whl

Total release size: 22.1 kB

Release files / pytypegen-1.0.4.tar.gz

Download URL pytypegen-1.0.4.tar.gz
Size 9.7 kB
Tags Source
SHA-256 checksum
How to use checksums
81754550e56e3afa202525331ab0d91a0eafef61d000e4217e614ebb14c07b60
BLAKE2b-256 checksum
How to use checksums
acf076919022600139cf32ef83125191557e758b32fad9c06cc1880776d1c706
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

Release files / pytypegen-1.0.4-py3-none-any.whl

Download URL pytypegen-1.0.4-py3-none-any.whl
Size 12.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0efd36cf353a45a6e3de8b868eddbaf19bd0f379be1fed1b35dd2f57ab4506f9
BLAKE2b-256 checksum
How to use checksums
bd69a716999f529a25a8868885e2ea07209ee4659cb3ac6a72bc56ed8f2ca5d0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

Security for pytypegen 1.0.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page