Hacker News

Hacker News

Show HN: A faster Python 3 interpreter implemented in C11, one week
2 points by soasme •                         
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

gregzem •                         
Can you suggest any use-cases for the spy? Are you using it already in your projects?