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

@lewin671/python-vm

v0.1.7

Published

A powerful, high-performance Python 3 Virtual Machine and Compiler engineered in pure TypeScript.

Downloads

885

Readme

@lewin671/python-vm

License NPM Version

A high-performance Python compiler and Virtual Machine (VM) implemented entirely in TypeScript. This project aims to provide a robust, Python-compliant execution environment within the JavaScript ecosystem, featuring a complete compilation pipeline from source code to bytecode.

简体中文

🚀 Key Highlights

  • Advanced Compilation Pipeline: Moves beyond simple interpretation by implementing a multi-stage pipeline: Source → Tokens → AST → Control Flow Graph (CFG) → Linear Bytecode → VM.
  • Python-Strict Semantics: Carefully implemented data structures (PyDict, PySet, PyList) that strictly follow Python's rules for equality, hashing, and numeric types (including BigInt for arbitrary-precision integers and NaN handling).
  • Comprehensive Language Support:
    • Core: Full support for functions, classes, closures, and decorators.
    • Modern Features: Includes match statements (Structural Pattern Matching), with statements (Context Managers), and try/except/finally blocks.
    • Control Flow: Robust handling of generators (yield), list/dict/set comprehensions, and nested scopes (global, nonlocal).
  • Production-Ready Tooling: Includes a high-fidelity Lexer with indentation/dedentation logic, a recursive descent Parser, and a stack-based VM.

🛠 Features

Compiler & VM

  • [x] Lexer: Handles complex Python indentation, f-strings, and multi-line literals.
  • [x] Parser: Generates a typed AST supporting a wide subset of Python 3.10+ syntax.
  • [x] CFG Builder: Optimizes code structures into a Control Flow Graph before bytecode generation.
  • [x] Bytecode Virtual Machine: A stack-based execution engine with local/global scope management.
  • [x] Exception System: Full traceback support and Python-compliant exception hierarchy.

Standard Library & Built-ins

  • Data Types: int, float, str, bool, list, tuple, dict, set, None.
  • Iteration: range, enumerate, zip, reversed, map, filter, sorted.
  • Utilities: abs, round, sum, min, max, isinstance, type, print, open, next.

📦 Installation

npm install @lewin671/python-vm

📖 Usage

Running via CLI

After cloning the repository, you can run Python files directly:

npm run build
npm start -- examples/hello.py

AOT Compilation (Ahead-Of-Time)

You can compile Python source files to a compressed binary bytecode format (.pyc) and execute them later. This avoids parsing overhead at runtime.

# 1. Compile source to bytecode
npm start -- compile examples/hello.py hello.pyc

# 2. Run the bytecode directly
npm start -- run hello.pyc

Using in your TypeScript project

import { PythonCompiler } from '@lewin671/python-vm';

const compiler = new PythonCompiler();

// Execute code directly
const result = compiler.run(`
def greet(name):
    return f"Hello, {name}!"

result = [greet(x) for x in ["World", "TypeScript"]]
print(result)
`);

// Or run a file
// compiler.runFile('./script.py');

🧪 Testing and Correctness

Correctness is a top priority. The project includes an extensive test suite using Vitest that compares the VM output against the system's CPython interpreter for parity.

# Run all tests (requires Python 3 installed locally)
npm test

⚖️ License

This project is licensed under the MIT License - see the LICENSE file for details.