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

ts-to-pyodide

v0.1.1

Published

Generate Python runtime wrappers from TypeScript .d.ts files for Pyodide

Readme

ts-to-pyodide

Generate Python runtime wrappers from TypeScript .d.ts type definitions for Pyodide.

Parses .d.ts files and produces Python classes that wrap the underlying JS objects via Pyodide's JsProxy, giving you typed, Pythonic access to JavaScript objects and functions.

Install

npm install -g ts-to-pyodide

Usage

The input directory must contain a tsconfig.json and the TypeScript type definitions you want to convert.

Generate Python wrappers

npx ts-to-pyodide render <input-dir> <output.py>

This produces two files:

  • <output.py> — the generated wrapper classes
  • prelude.py — runtime helpers that is imported by <output.py> (written next to <output.py>)

Render only specific bindings

Use --only to render specific classes and their transitive dependencies:

npx ts-to-pyodide render <input-dir> <output.py> --only KVNamespace,R2Bucket,D1Database

This is useful when working with large type packages like @cloudflare/workers-types — instead of generating wrappers for all 700+ interfaces, you get only the ones you need.

Output raw IR as JSON

npx ts-to-pyodide ir <input-dir> <output.json>

Example: Cloudflare Workers types

mkdir my-project && cd my-project

cat > package.json << 'EOF'
{
  "dependencies": {
    "@cloudflare/workers-types": "*",
    "typescript": "~5.3.0"
  }
}
EOF

cat > tsconfig.json << 'EOF'
{
  "compilerOptions": {
    "target": "esnext",
    "module": "esnext",
    "moduleResolution": "nodenext",
    "lib": ["esnext"],
    "types": ["@cloudflare/workers-types"]
  },
  "include": ["node_modules/@cloudflare/workers-types/index.d.ts"]
}
EOF

npm install

# Generate wrappers for KV, R2, and D1 only
npx ts-to-pyodide render . bindings.py --only KVNamespace,R2Bucket,D1Database

# Or generate everything
npx ts-to-pyodide render . bindings.py

Output structure

The generated bindings.py imports from prelude.py (which is placed alongside it):

from __future__ import annotations
from prelude import *

class KVNamespace:
    _binding: Any

    @classmethod
    def from_js(cls, js_obj: JsProxy) -> KVNamespace:
        ...

    async def get(self, key: str) -> str | None:
        return _jsnull_to_none(await self._binding.get(key))

    async def put(self, key: str, value: str) -> None:
        await self._binding.put(key, value)
    ...

Using the generated wrappers in Pyodide

from bindings import KVNamespace

# Wrap an existing JS binding (e.g. from env)
kv = KVNamespace.from_js(env.MY_KV)

# Use with Python syntax
value = await kv.get("my-key")
await kv.put("my-key", "hello")

Development

npm install
npm test          # Run all tests
npm run check     # TypeScript type check
npm run build     # Compile to dist/