Skip to content

Introduction

python2ts bridges the gap between AI’s favorite language and the world’s largest ecosystem.

Python dominates AI, ML, and data science. TypeScript powers modern web applications with the npm ecosystem of 3+ million packages. python2ts brings them together — transpile Python to production-ready TypeScript with full type safety.

The Numbers

MetricValue
Tests2000+
Python Modules20+
Dependencies0 (pythonlib)
Runtimes Supported4 (Node.js, Bun, Deno, Browser)
Python Features15+ major constructs

Why python2ts?

AI-First Workflow

Python dominates AI/ML. TypeScript powers modern web apps. Bridge the gap—prototype in Python, deploy anywhere JavaScript runs.

Full Type Safety

Python type hints become TypeScript types automatically. Generics, Protocols, TypedDicts, Callable—all preserved.

20+ Python Modules

itertools, functools, collections, datetime, re, os, pathlib, hashlib, uuid, base64, glob, shutil, tempfile, and more.

Run Everywhere

Node.js, Deno, Bun, browsers, Cloudflare Workers, AWS Lambda—anywhere JavaScript runs, your code runs too.

Two Packages, One Solution

PackageDescriptionDependencies
python2tsThe transpiler CLI and APIMinimal
pythonlibPython standard library for TypeScript (20+ modules)Zero

Use them together or separately — pythonlib works standalone if you just want Python’s itertools, functools, or collections in TypeScript.

Quick Example

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

Becomes:

import { range } from "pythonlib"
/**
* Generate Fibonacci sequence.
*/
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
}
console.log(fibonacci(10))

What’s in pythonlib?

A comprehensive implementation of Python’s most useful modules:

Core Utilities

ModuleHighlights
itertoolscombinations, permutations, product, chain, cycle, groupby
functoolslruCache, partial, reduce, pipe, compose
collectionsCounter, defaultdict, deque, OrderedDict

Data & Time

ModuleHighlights
datetimedatetime, date, time, timedelta with full arithmetic
jsonloads, dumps with Python-compatible semantics
research, match, findAll, sub with named groups

Math & Random

ModuleHighlights
mathsqrt, floor, ceil, factorial, gcd, pi, e
randomrandInt, choice, shuffle, sample, uniform

File System

ModuleHighlights
ospath.join, environ, getcwd, listdir, walk
pathlibPath class with readText, writeText, glob
globPattern matching for files
shutilcopy, move, rmtree
tempfileNamedTemporaryFile, TemporaryDirectory

Security & Encoding

ModuleHighlights
hashlibmd5, sha256, sha512
base64b64encode, b64decode, URL-safe variants
uuiduuid4, uuid1, UUID class

More

ModuleHighlights
stringTemplate, capWords, ASCII constants
subprocessrun, call, checkOutput
urlliburlparse, urljoin, quote
logginggetLogger, basicConfig, handlers
sysargv, platform, exit
timesleep, time, strftime
copycopy, deepcopy

Supported Python Features

FeatureStatus
Functions & type hints
Classes & inheritance
Dataclasses
Generics (TypeVar, Generic)
Protocols
TypedDict
List/dict/set comprehensions
Pattern matching (match)
Async/await
Decorators
Context managers (with)
f-strings
Generators
Walrus operator (:=)
Multiple inheritance

Runtime Support

Tested on every commit:

  • Node.js v22, v24
  • Bun latest
  • Deno v2.x
  • Browsers via Playwright (Chrome, Firefox, Safari)

Also works in: Cloudflare Workers, AWS Lambda, Vercel Edge Functions, and any other JavaScript runtime.