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

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

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.

Is missing Python stdlib a pain? Probably no. Host injected modules allows any language's ecosystem to be used in Python syntax. Check examples, you can build game by using Raylib, or build web server using Axum/Serde_python (using Rust crates).

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. You can install via pip, npm, crate, go. Worker mode is recommended so that any issue would be contained in a subprocess.

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.

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.

It's using a full suite of tests: unittest, fuzz, sanitize, bench, TLA+ specs. Despite using C, agents are unable to spot a single segfault as of now. So that's pretty cool. :)

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

It has been built for one week. I have a long Claude Code session running over several days with /remote-control using Opus 5.5.

Repo url: https://github.com/soasme/small-python Previous HN post: https://news.ycombinator.com/item?id=50281226

2 comments

[ 0.28 ms ] story [ 12.1 ms ] thread
Can you suggest any use-cases for the spy? Are you using it already in your projects?
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.

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. (To my knowledge, no Python tool can compress a Python based game down to <2MB).

---

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