npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

python2ts

v1.4.3

Published

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

Downloads

1,355

Readme

python2ts

Transpile Python to TypeScript — Automatically

npm version npm downloads CI TypeScript License


Stop rewriting Python code by hand. python2ts transforms your Python into clean, idiomatic TypeScript — with full type preservation.

Install

npm install -g python2ts

Usage

# Transpile a file
python2ts algorithm.py -o algorithm.ts

# Transpile to stdout
python2ts script.py

# Pipe from stdin
cat utils.py | python2ts > utils.ts

What It Does

Your Python

from dataclasses import dataclass
from collections import Counter

@dataclass
class WordStats:
    text: str

    def word_count(self) -> dict[str, int]:
        words = self.text.lower().split()
        return dict(Counter(words))

    def most_common(self, n: int = 5):
        counts = Counter(self.word_count())
        return counts.most_common(n)

Clean TypeScript

import { Counter } from "pythonlib/collections"

class WordStats {
  constructor(public text: string) {}

  wordCount(): Map<string, number> {
    const words = this.text.toLowerCase().split(/\s+/)
    return new Map(new Counter(words))
  }

  mostCommon(n: number = 5) {
    const counts = new Counter(this.wordCount())
    return counts.mostCommon(n)
  }
}

Supported Python Features

| Feature | Example | Output | | ------------------------ | ----------------------------- | --------------------------------------------- | | Type hints | def foo(x: int) -> str: | function foo(x: number): string | | Dataclasses | @dataclass class Point: | class Point { constructor... } | | List comprehensions | [x*2 for x in items] | items.map(x => x * 2) | | Dict comprehensions | {k: v for k, v in pairs} | new Map(pairs.map(...)) | | Pattern matching | match x: case 1: ... | switch/if statements | | f-strings | f"Hello {name}!" | `Hello ${name}!` | | Async/await | async def fetch(): | async function fetch() | | Decorators | @lru_cache def fib(n): | Transformed decorators | | Context managers | with open(f) as file: | try/finally blocks | | Generators | yield from items | yield* items | | Walrus operator | if (n := len(x)) > 0: | let n; if ((n = len(x)) > 0) | | Multiple inheritance | class C(A, B): | Mixins | | Standard library | from itertools import chain | import { chain } from "pythonlib/itertools" |

CLI Options

Usage: python2ts [options] [file]

Arguments:
  file                    Python file to transpile (reads from stdin if omitted)

Options:
  -o, --output <file>     Write output to file instead of stdout
  -r, --runtime <path>    Custom runtime library path (default: "pythonlib")
  --no-runtime            Don't add runtime imports
  -v, --version           Show version number
  -h, --help              Show help

Programmatic API

import { transpile } from "python2ts"

const python = `
def greet(name: str) -> str:
    return f"Hello, {name}!"
`

const typescript = transpile(python)
console.log(typescript)
// function greet(name: string): string {
//   return `Hello, ${name}!`
// }

Runtime Library

The transpiled code uses pythonlib for Python standard library functions. Install it as a dependency in your project:

npm install pythonlib

Documentation

| Resource | Description | | ------------------------------------------------------------------------------ | ------------------------------ | | Homepage | Project overview and features | | Getting Started | Installation and first steps | | Syntax Reference | Complete transformation rules | | API Reference | Programmatic API documentation |

Runtime Support

Transpiled code runs everywhere JavaScript runs:

  • Node.js (v22, v24)
  • Bun
  • Deno
  • Browsers
  • Edge (Cloudflare Workers, AWS Lambda, Vercel)

Related

  • pythonlib — Python standard library for TypeScript
  • GitHub — Source code, issues, contributions welcome

License

MIT © Sebastian Software GmbH