Skip to main content

Python-Interoperability for Typescript-Interfaces

Project description

ts2py

Python-interoperability for Typescript-Interfaces. Transpiles TypeScript-Interface-definitions to Python TypedDicts

What is this

This repo is born as a fork of ts2python written by Eckhart Arnold arnold@badw.de, Bavarian Academy of Sciences and Humanities. The reason behind this fork was that I needed a simpler way to quickly convert TypeScript interfaces to Python TypedDict. Once I started looking into the initial code I decided to change (and remove) a lot of stuff. I also managed to split the code in multiple files and added Typer to create a beautiful CLI. The initial project should be much more powerful and should also have support for run-time type-checking of JSON-data.

Purpose

Nowadays a lot of applications are created with TypeScript. To enable a much better way of developing when dealing with Python backend it could be useful to quickly convert Typescript-Interfaces into Python TypedDicts. In order to enable structural validation on the Python-side, ts2py transpiles the typescript-interface definitions to Python-data structure definitions.

Installation

ts2py can be installed from the command line with the command:

pip install ts2py

ts2py requires the parsing-expression-grammar-framework DHParser which will automatically be installed as a dependency by the pip-command. ts2py requires at least Python Version 3.10 to run. However, the Python-code it produces is backwards compatible down to Python 3.6 thanks to the typing extensions.

Usage

In order to generate TypedDict-classes from Typescript-Interfaces, run ts2py on the Typescript-Interface definitions:

ts2py interfaces.ts

This generates a .py file in same directory as the source file that contains the TypedDict-classes and can simpy be imported in Python-Code:

from interfaces import *

License and Source Code

ts2py is open source software under the Apache 2.0 License

The complete source-code of ts2py can be downloaded from the its git-repository.

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

ts2py-0.0.2.tar.gz (23.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ts2py-0.0.2-py3-none-any.whl (26.0 kB view details)

Uploaded Python 3

File details

Details for the file ts2py-0.0.2.tar.gz.

File metadata

  • Download URL: ts2py-0.0.2.tar.gz
  • Upload date:
  • Size: 23.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.10.9 Linux/5.15.0-1030-azure

File hashes

Hashes for ts2py-0.0.2.tar.gz
Algorithm Hash digest
SHA256 b3d447287954beca56b4609c7065d3e6b1dc1782a43f662519872fab93f08091
MD5 745ba9198a4698520256bcd62e19a9dd
BLAKE2b-256 b08d64e4ee354ba87fa9a8b843555c356f5dbd9636d8cf06d15ce031024214b3

See more details on using hashes here.

File details

Details for the file ts2py-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: ts2py-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 26.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.10.9 Linux/5.15.0-1030-azure

File hashes

Hashes for ts2py-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4c71bc44cb3c23bb610f207bdc0f88dcaf1026fab90f30d688ac92608e9f934f
MD5 1b893fb7eb327b6ff716ddffbd35f872
BLAKE2b-256 4fad1ddf7d64f63ca7f7ca271f1e60a8e05b5cee708bd586847afe110116c817

See more details on using hashes here.

Supported by

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