Python type code generator
Project description
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.
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
pytypegen-1.0.4.tar.gz
(9.7 kB
view hashes)
Built Distribution
pytypegen-1.0.4-py3-none-any.whl
(12.4 kB
view hashes)
Close
Hashes for pytypegen-1.0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0efd36cf353a45a6e3de8b868eddbaf19bd0f379be1fed1b35dd2f57ab4506f9 |
|
MD5 | 3b8625736cc9b591779b2f46463b7ea2 |
|
BLAKE2b-256 | bd69a716999f529a25a8868885e2ea07209ee4659cb3ac6a72bc56ed8f2ca5d0 |