paiml/depyler
Compiles Python to Rust, helping transition off of Python to Energy Efficient and Safe Rust Code
What it solves
Depyler bridges the gap between Python's rapid development and Rust's performance and safety guarantees. It converts Python code that has type annotations into idiomatic Rust, preserving the original program semantics while adding compile-time safety checks. This saves developers from manually rewriting code in Rust, and it enables Python-based projects to produce native binaries without abandoning the Python ecosystem.
How it works
Depyler parses Python source into an abstract syntax tree (AST), then transforms it through a high-level intermediate representation (HIR). During this process, it performs type inference (guided by Python annotations) and memory safety analysis to determine ownership and borrowing patterns. The final stage generates Rust code using the syn/quote libraries. Users can either transpile Python to a Rust file (depyler transpile) or compile directly to a standalone binary (depyler compile). An optional --verify flag runs property-based tests to confirm the generated Rust behaves identically to the original Python.
Who it’s for
Depyler is aimed at developers who want to move Python codebases to Rust, especially those that already use type hints. It also appeals to teams looking to compile Python into native executables for speed while keeping Rust's memory safety. The project is part of the PAIML Stack and has documented success across several corpora, including standard library modules and algorithm examples.
Highlights
- One-command compilation:
depyler compile script.pyproduces a native executable. - Semantic verification integrates property-based testing to ensure behavior matches the original Python.
- Memory safety analysis automatically infers ownership and borrowing rules.
- 27 Python standard library modules are validated (from json to datetime to os) with 151 passing tests.
- Single-shot compile rate of 80% on internal examples (256/320) and 92.7% on a Tier-1 stdlib corpus.
- Usable as a Rust library through the
transpile_fileAPI. - Active development with a clear architecture: Python AST → HIR → Type Inference → Rust AST → Code Generation.
Related
- Project
- Project
- Project
- Project