Python is an incredibly productive language. But when it comes to performance, native interoperability and application distribution, there are still interesting problems to solve.

What if we could keep writing Python while compiling it into native executables?

That's the idea behind Pyrock, an experimental open-source Python compiler I've been developing at Abstrkshen.

The experiment

Pyrock takes supported Python source code, performs type inference, generates Rust code and compiles it into a native executable.

The goal is to preserve familiar Python syntax while taking advantage of native compilation wherever possible.

Python source ↓ AST parsing ↓ Type inference ↓ Rust code generation ↓ Native compilation ↓ Executable 

Performance

In one of my numeric-loop benchmarks, Pyrock achieved approximately 50× faster execution than CPython.

In another demonstration, the same Python program produced identical output while running significantly faster.

The resulting native executable was approximately 458 KB and did not require a Python interpreter to run.

These results are workload-specific. They do not mean that every Python program will automatically become 50× faster.

Importing Rust and C directly

One of the features I'm particularly interested in is native language interoperability.

Instead of manually creating bindings, Pyrock allows supported Python programs to import Rust and C source files directly.

The compiler handles the integration during the build process.

The idea is to make Python a convenient entry point for software that also needs native performance or access to existing native libraries.

Why build another Python compiler?

Projects such as Cython, Nuitka, Numba and mypyc already address different aspects of Python performance and compilation.

Pyrock is an experiment exploring a particular combination of goals:

  • Familiar Python syntax.
  • Automatic type inference.
  • Native executable generation.
  • Direct Rust and C interoperability.
  • Minimal runtime dependencies for supported programs.
  • Transparent reporting of what can and cannot be compiled natively.

I'm interested in how much of Python can be compiled without sacrificing the developer experience that makes the language attractive in the first place.

The difficult part: Python semantics

Generating Rust code is only part of the problem.

Python's dynamic behavior introduces significant challenges:

  • Dynamic typing.
  • Runtime attribute resolution.
  • Arbitrary-precision integers.
  • Dynamic function dispatch.
  • Exception handling.
  • Third-party package compatibility.
  • Object identity and mutation.

Pyrock is still experimental. Some operations compile natively, while others still depend on CPython.

Current limitations include fixed-width integers in native execution paths, limited traceback information and incomplete native compilation coverage.

I want to be transparent about these limitations rather than claim that Pyrock is a complete replacement for CPython.

See it in action

I've recorded a demonstration covering native compilation, performance, standalone executable distribution and Rust/C interoperability.

https://www.youtube.com/watch?v=Byc9DSE2IeQ

You can explore the source code here:

https://github.com/Abstrkshen/pyrock

The project is open source under MIT/Apache-2.0 licensing.

I'd love your feedback

I'm particularly interested in hearing from Python developers, Rust developers and anyone working on compilers.

  • What Python workloads would you want to compile natively?
  • Would direct Rust and C imports be useful in your projects?
  • How much Python compatibility would you need before considering a compiler like this?
  • What benchmarks would you like to see?

Technical criticism, suggestions and contributions are welcome.

Built at Abstrkshen, an independent technology and research initiative.

https://abstrkshen.com/