← All projects
Project record2 mentions
Originally shared on Hacker News

Small Python (spy)

Small Python (spy) is a small, embeddable Python engine written in C11, comparable to quickjs for JavaScript. The entire Python core language is implemented with almost all builtins (no stdlib except sys/gc); it can be used as a C library via spy.h/spyc-*.c or through bindings for Js, Python, Rust, and Go. It supports host injected modules (e.g., Raylib for games, Axum/Serde_python from Rust crates), runs slightly faster than CPython in most benched cases, and can compile Python apps into small binaries (a raylib PONG game at ~2MB). It is also used by the author as the execution engine for running codemode in a personal coding agent, with a roadmap targeting agent use cases like snapshot/resume across durable sessions.

Last shared
01 / The problem

What it addresses

Python lacks a small, embeddable interpreter like quickjs is for JavaScript, and bundling Python apps with PyInstaller produces large binaries.

02 / Source history

Shared over time

Each entry reflects what was shared on that date. Details may have changed since then.

  1. Small Python (spy)

    Small Python (spy) is a small, embeddable Python engine written in C11, comparable to quickjs for JavaScript. The entire Python core language is implemented with almost all builtins (no stdlib except sys/gc); it can be used as a C library via spy.h/spyc-*.c or through bindings for Js, Python, Rust, and Go. It supports host injected modules (e.g., Raylib for games, Axum/Serde_python from Rust crates), runs slightly faster than CPython in most benched cases, and can compile Python apps into small binaries (a raylib PONG game at ~2MB). It is also used by the author as the execution engine for running codemode in a personal coding agent, with a roadmap targeting agent use cases like snapshot/resume across durable sessions.

    Problem: Python lacks a small, embeddable interpreter like quickjs is for JavaScript, and bundling Python apps with PyInstaller produces large binaries.

    Posted by @soasme · Original source ↗

    Story title · @soasme · · Source ↗

    Show HN: A faster Python 3 interpreter implemented in C11, one week

    Source text · @soasme · · Source ↗

    Small Python (spy) is a small, embeddable Python engine written in C11. Pretty much like quickjs for javascript, it's for Python.

    Source text · @soasme · · Source ↗

    https://github.com/soasme/small-python

    Source text · @soasme · · Source ↗

    The entire Python core language features is full implemented with almost all builtins. No Lib/ is included except sys/gc that changes the interpreter behaviors.

    Source text · @soasme · · Source ↗

    Just copy `spy.h`, `spyc-*.c` into your project and use it as a C library. Or several bindings are provided for languages like Js, Python, Rust, Go.

    Source text · @soasme · · Source ↗

    It's fast. Well, not at the speed of Pypy because it's not JIT. But it's slightly faster than C Python in most benched cases.

    Source text · @soasme · · Source ↗

    Another good feature is compiling Python into a binary. You could use PyInstaller, but it's gonna be so large. Small Python's binary is small. A raylib + spy based PONG game is built at around 2MB.

    Source text · @soasme · · Source ↗

    The roadmap aims to build it for agents: snapshot/resume between durable sessions, policy declaration so agents never shoot on your feet, etc.

    Source text · @soasme · · Source ↗

    Small Python can be used as a smaller & faster replacement of pydantic-monty if std lib is not a concern, E.g, it is great for AI agents to run untrusted code.

    Source text · @soasme · · Source ↗

    Small Python can also be used for making games, Desktop GUI or anytime whe you want to write Python code and ship into a small binary.

    Source text · @soasme · · Source ↗

    I do use it in my personal coding agent, using small-python as the execution engine for running codemode.
  2. Small Python

    Small Python is a quickjs-like implementation of Python written in plain C11 (~25k lines of code), covering almost full Python 3.15 language features and builtins but not Lib/ support, suited for embedding scenarios.

    Posted by @soasme · Original source ↗

    Story title · @soasme · · Source ↗

    Show HN: Full Python 3.15 Implemented in 25k LoC C11

    Source text · @soasme · · Source ↗

    I burned about $500 for this fun project: Small Python.

    Source text · @soasme · · Source ↗

    The outcome is a quickjs-like implementation for Python.

    Source text · @soasme · · Source ↗

    Almost full Python 3.15 language features plus builtins are covered.

    Source text · @soasme · · Source ↗

    No Lib/ support.

    Source text · @soasme · · Source ↗

    No rust. Just plain C11 code.

    Source text · @soasme · · Source ↗

    Great for embedding scenarios.

    Source text · @soasme · · Source ↗

    Repo is here: https://github.com/soasme/small-python/