JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 8
  • Score
    100M100P100Q55548F
  • License MIT

AST-based Python to TypeScript transpiler. Convert Python code to clean, idiomatic TypeScript with full type preservation.

Package Exports

  • python2ts

Readme

python2ts

npm version npm downloads CI TypeScript License

AST-based Python to TypeScript transpiler — Write Python, ship TypeScript.

Convert Python code to clean, idiomatic TypeScript with full type preservation.

Quick Start

npm install python2ts
# Transpile a file
npx python2ts input.py -o output.ts

# Pipe from stdin
cat script.py | npx python2ts > script.ts

Example

def fibonacci(n: int) -> list[int]:
    a, b = 0, 1
    result = []
    for _ in range(n):
        result.append(a)
        a, b = b, a + b
    return result

Becomes:

import { range } from "pythonlib"

function fibonacci(n: number): number[] {
  let [a, b] = [0, 1]
  let result: number[] = []
  for (const _ of range(n)) {
    result.push(a)
    ;[a, b] = [b, a + b]
  }
  return result
}

Documentation

📚 View Full Documentation

Resource Description
Homepage Project overview, features, and quick start
Getting Started Installation and first steps
Syntax Reference Python → TypeScript transformation rules
Runtime Library Using pythonlib for Python standard library
API Reference Complete API documentation

Runtime Support

Tested on every commit: Node.js (v22, v24) · Bun · Deno · Browsers

  • pythonlib — Python standard library for TypeScript
  • GitHub — Source code and issue tracker

License

MIT © Sebastian Software GmbH