{"id":15673346,"url":"https://github.com/thelartians/typescript2python","last_synced_at":"2025-04-15T16:59:47.198Z","repository":{"id":215447555,"uuid":"738665130","full_name":"TheLartians/TypeScript2Python","owner":"TheLartians","description":"🚃 Transpile TypeScript types to Python! A TypeScript to Python type transpiler.","archived":false,"fork":false,"pushed_at":"2025-01-21T16:32:37.000Z","size":49,"stargazers_count":21,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-28T22:42:19.202Z","etag":null,"topics":["api","auto-generated","compiler","conversion","converter","docstrings","documentation","generator","json","python","python3","to","tooling","transpiler","type-checking","type-safety","typescript","typings"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/typescript2python","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TheLartians.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-01-03T18:53:33.000Z","updated_at":"2025-03-08T08:15:26.000Z","dependencies_parsed_at":"2024-01-04T14:28:01.845Z","dependency_job_id":"71be8199-db82-4c78-b641-09b7be31ed28","html_url":"https://github.com/TheLartians/TypeScript2Python","commit_stats":{"total_commits":36,"total_committers":2,"mean_commits":18.0,"dds":0.5,"last_synced_commit":"cd829536c8f1ed5b677bd3b62655981538f98b2c"},"previous_names":["thelartians/typescript2python"],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheLartians%2FTypeScript2Python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheLartians%2FTypeScript2Python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheLartians%2FTypeScript2Python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheLartians%2FTypeScript2Python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TheLartians","download_url":"https://codeload.github.com/TheLartians/TypeScript2Python/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248688571,"owners_count":21145766,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","auto-generated","compiler","conversion","converter","docstrings","documentation","generator","json","python","python3","to","tooling","transpiler","type-checking","type-safety","typescript","typings"],"created_at":"2024-10-03T15:40:01.413Z","updated_at":"2025-04-15T16:59:47.186Z","avatar_url":"https://github.com/TheLartians.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TypeScript2Python\n\n## About\n\nThis project implements a transpiler for creating [pyright](https://github.com/microsoft/pyright) compatible type declarations automatically from TypeScript code! \nThis is useful in a number of scenarios.\nFor example:\n\n- Safely use JSON objects created by TypeScript projects in Python\n- Automatic generation of type-safe APIs between Node.js and Python applications\n- An easy way to write complex Python typings using TypeScript\n\n## Example\n\n### TypeScript\n\n```ts\nexport type Foo = {\n    type: \"foo\"\n    foo: number[]\n    optional?: string\n}\n\n/** DocStrings are supported! */\nexport type Bar = {\n    type: \"bar\"\n    bar: string\n    /** nested objects need extra declarations in Python */\n    nested: { \n        foo: Foo\n    }\n}\n\nexport type FooBarMap = { \n    [key: string]: Foo | Bar\n}\n\nexport type TupleType = [string, Foo | Bar, any[]]\n```\n\n### TypeScript2Python\n\n```python\nfrom typing_extensions import Any, Dict, List, Literal, NotRequired, Tuple, TypedDict, Union\n\nclass Foo(TypedDict):\n  type: Literal[\"foo\"]\n  foo: List[float]\n  optional: NotRequired[str]\n\nclass Ts2Py_tliGTOBrDv(TypedDict):\n  foo: Foo\n\nclass Bar(TypedDict):\n  \"\"\"\n  DocStrings are supported!\n  \"\"\"\n  type: Literal[\"bar\"]\n  bar: str\n  nested: Ts2Py_tliGTOBrDv\n  \"\"\"\n  nested objects need extra declarations in Python\n  \"\"\"\n\nFooBarMap = Dict[str,Union[Foo,Bar]]\n\nTupleType = Tuple[str,Union[Foo,Bar],List[Any]]\n```\n\n\n## Usage\n\nThe easiest way to use TypeScript2Python, is to invoke it directly using `npx` and pointing it to one (or multiple) source files that export type declarations.\n\n```bash\nnpx typescript2python \u003cpath to typescript source\u003e\n```\n\nIt will then output the transpiled code to the terminal.\nTo save the output as a python file, simply pipe the result to the desired destination.\nFor example `npx typescript2python types.ts \u003e types.py`.\n\n## Features\n\nTypeScript2Python supports many of TypeScripts type constructs, including:\n\n- Basic types, like `boolean`, `number`, `string`, `undefined`\n- Literal types, e.g. `type X = 42`, `type Y = 'test'`\n- Object types, `{ foo: string }`\n- Unions, `string | number`\n- Arrays, `boolean[]`\n- Nested objects `{ bar: { foo: string } }`, that will get transpiled into helper dictionaries\n- Optional properties `{ optional?: number }`, that get transpiled to `NotRequired[...]` attributes\n- Docstrings `/** this is very useful */`\n\n## Transpiler options\n\n### Strict\n\nUse the `--strict` flag to enable all strict type-checking options to ensure `undefined` and `null` properties are not ignored during transpilation.\n\n### Nullable optionals\n\nIn TypeScript objects, optional values can also be set to `undefined`. By default we assume the according Python\ntype to be non-nullable, but a more closely matching behavior can be achieved using the flag `--nullable-optionals`.\nThis will result in optional entries beeing transpiled as `NotRequired[Optional[T]]` instead of `NotRequired[T]`.\n\n## Limitations\n\nThe main focus of this project is transpiling type definitions for serializable data (e.g. JSON objects), and the following is not planned to be supported:\n\n- Generics, as TypeScript's type system is much more powerful than Python's\n- Function signatures, as we restrict ourselves to serializable data\n- Anything that isn't a type definition\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthelartians%2Ftypescript2python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthelartians%2Ftypescript2python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthelartians%2Ftypescript2python/lists"}