Skip to main content
Join the official 2019 Python Developers SurveyStart the survey!

Python type code generator

Project description

Build Status codecov pyup


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


  • Python 3.7 (need dataclass)


pip install pytypegen


from pytypgen.core import contracts_to_typescript, Contract

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

class Address(Contract):
    street: str

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.

Project details

Download files

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

Files for pytypegen, version 1.0.4
Filename, size File type Python version Upload date Hashes
Filename, size pytypegen-1.0.4-py3-none-any.whl (12.4 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size pytypegen-1.0.4.tar.gz (9.7 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page