Skip to content

python2ts v1.0.0

Choose a tag to compare

@swernerx swernerx released this 19 Jan 23:03
20a614a

python2ts v1.0.0 🎉

First stable release of python2ts - AST-based Python to TypeScript transpiler.

Features

  • AST-based transformation - Accurate parsing with @lezer/python
  • Type preservation - Python type hints become TypeScript types
  • Clean output - Idiomatic TypeScript code with Prettier formatting
  • Comprehensive support - Classes, functions, decorators, comprehensions, etc.
  • Runtime library - pythonlib provides Python builtins in TypeScript

Example

Python input:
```python
from typing import List

def greet(names: List[str]) -> str:
return ", ".join(f"Hello {name}!" for name in names)
```

TypeScript output:
```typescript
function greet(names: string[]): string {
return names.map((name) => `Hello ${name}!`).join(", ")
}
```

Installation

```bash
npm install python2ts
```

Usage

```bash

CLI

npx python2ts input.py -o output.ts

Programmatic

import { transpile } from "python2ts"
const typescript = transpile(pythonCode)
```

Links