A Python library for seamless type conversion between Python and TypeScript, facilitating interoperability in multi-language projects.
- Convert Python type annotations to TypeScript types
- Convert TypeScript type definitions back to Python annotations
- Support for:
- Basic types (str, int, float, bool, None)
- Complex types (List, Dict, Tuple, Union, Optional)
- Literal types
- Pydantic models to TypeScript interfaces
- Type metadata preservation
- Multi-line docstring conversion
pip install crimson-py-ts-types-beta
The following examples demonstrate key features and use cases of the library. Each notebook contains detailed code samples and explanations.
-
Quick Start Guide
Basic setup and overview of Python-TypeScript type conversion, including type mapping and bi-directional conversion examples. -
Positive Conversion (Python → TypeScript)
Detailed explanation of converting Python type annotations to TypeScript, focusing on AST-based conversion process. -
Negative Conversion (TypeScript → Python)
Implementation details of converting TypeScript types back to Python annotations without relying on TypeScript parser.
- Pydantic Model Interface Generation
Examples of converting Pydantic models to TypeScript interfaces while preserving:- Field types and optionality
- Documentation and descriptions
- Default values
- Custom metadata
Each notebook is self-contained and includes:
- Detailed explanations of the concepts
- Working code examples
- Edge cases and their solutions
- Complete input/output demonstrations