$git clone https://github.com/paiml/depylerA Python-to-Rust transpiler with semantic verification and memory safety analysis.
| 1 | <div align="center"> |
| 2 | <img src="docs/hero.svg" alt="depyler" width="800"> |
| 3 | |
| 4 | # depyler |
| 5 | |
| 6 | **A Python-to-Rust transpiler with semantic verification and memory safety analysis.** |
| 7 | |
| 8 | [](https://crates.io/crates/depyler) |
| 9 | [](https://docs.rs/depyler) |
| 10 | [](https://github.com/paiml/depyler/actions/workflows/ci.yml) |
| 11 | [](https://opensource.org/licenses/MIT) |
| 12 | </div> |
| 13 | |
| 14 | --- |
| 15 | |
| 16 | Depyler translates annotated Python code into idiomatic Rust, preserving program semantics while providing compile-time safety guarantees. Part of the [PAIML Stack](https://github.com/paiml). |
| 17 | |
| 18 | ## Table of Contents |
| 19 | |
| 20 | - [What's New in v4.1.1](#whats-new-in-v411) |
| 21 | - [Features](#features) |
| 22 | - [Installation](#installation) |
| 23 | - [Quick Start](#quick-start) |
| 24 | - [Usage](#usage) |
| 25 | - [Supported Python Features](#supported-python-features) |
| 26 | - [Stdlib Module Support](#stdlib-module-support) |
| 27 | - [Architecture](#architecture) |
| 28 | - [Documentation](#documentation) |
| 29 | - [Quality Metrics](#quality-metrics) |
| 30 | - [Contributing](#contributing) |
| 31 | - [License](#license) |
| 32 | |
| 33 | ## What's New in v4.1.1 |
| 34 | |
| 35 | - **`str(dict.get(key, default))` fix**: No longer generates spurious `.unwrap()` calls |
| 36 | - **25+ Python module mappings**: `tempfile`, `datetime`, `os`, `shutil`, `glob`, and more |
| 37 | - **E0433 import resolution**: Improved handling of unresolved imports |
| 38 | - **`[profile.test] opt-level=1`**: Faster test execution |
| 39 | |
| 40 | ### Multi-Corpus Convergence (v3.25.0+) |
| 41 | |
| 42 | All three external corpus targets met: |
| 43 | |
| 44 | | Corpus | Compile Rate | Target | |
| 45 | |--------|--------------|--------| |
| 46 | | Tier 1 (stdlib) | **92.7%** (38/41) | 80% | |
| 47 | | Tier 2 (typed-cli) | **62.5%** (10/16) | 60% | |
| 48 | | Tier 5 (algorithms) | **47.5%** (48/101) | 40% | |
| 49 | | Internal examples | **80%** (256/320) | 80% | |
| 50 | |
| 51 | ## Features |
| 52 | |
| 53 | - **Type-Directed Transpilation** — Uses Python type annotations to generate appropriate Rust types |
| 54 | - **Memory Safety Analysis** — Infers ownership and borrowing patterns automatically |
| 55 | - **Semantic Verification** — Property-based testing to verify behavioral equivalence |
| 56 | - **Single-Command Compilation** — Compile Python to native binaries with `depyler compile` |
| 57 | - **27 Stdlib Modules** — Production-ready support for common Python standard library modules |
| 58 | - **80%+ Single-Shot Compile Rate** — Most Python files compile on first transpilation attempt |
| 59 | |
| 60 | ## Installation |
| 61 | |
| 62 | ```bash |
| 63 | cargo install depyler |
| 64 | ``` |
| 65 | |
| 66 | ### Requirements |
| 67 | |
| 68 | - Rust 1.83.0 or later |
| 69 | - Python 3.8+ (for test validation) |
| 70 | |
| 71 | ## Quick Start |
| 72 | |
| 73 | ### Compile to Binary |
| 74 | |
| 75 | The fastest way to use Depyler: |
| 76 | |
| 77 | ```bash |
| 78 | # Compile Python to a standalone binary |
| 79 | depyler compile script.py |
| 80 | |
| 81 | # Run the compiled binary |
| 82 | ./script |
| 83 | ``` |
| 84 | |
| 85 | ### Transpile to Rust |
| 86 | |
| 87 | ```bash |
| 88 | # Transpile a Python file to Rust |
| 89 | depyler transpile example.py |
| 90 | |
| 91 | # Transpile with semantic verification |
| 92 | depyler transpile example.py --verify |
| 93 | ``` |
| 94 | |
| 95 | ### Example |
| 96 | |
| 97 | **Input** (`fibonacci.py`): |
| 98 | ```python |
| 99 | def fibonacci(n: int) -> int: |
| 100 | if n <= 1: |
| 101 | return n |
| 102 | return fibonacci(n - 1) + fibonacci(n - 2) |
| 103 | ``` |
| 104 | |
| 105 | **Output** (`fibonacci.rs`): |
| 106 | ```rust |
| 107 | fn fibonacci(n: i32) -> i32 { |
| 108 | if n <= 1 { |
| 109 | return n; |
| 110 | } |
| 111 | fibonacci(n - 1) + fibonacci(n - 2) |
| 112 | } |
| 113 | ``` |
| 114 | |
| 115 | ## Usage |
| 116 | |
| 117 | ### Compilation Options |
| 118 | |
| 119 | ```bash |
| 120 | # Compile with custom output name |
| 121 | depyler compile script.py -o my_app |
| 122 | |
| 123 | # Debug build (faster compilation) |
| 124 | depyler compile script.py --profile debug |
| 125 | |
| 126 | # Release build (optimized, default) |
| 127 | depyler compile script.py --profile release |
| 128 | ``` |
| 129 | |
| 130 | ### Transpilation Options |
| 131 | |
| 132 | ```bash |
| 133 | # Show transpilation trace |
| 134 | depyler transpile example.py --trace |
| 135 | |
| 136 | # Explain transformation decisions |
| 137 | depyler transpile example.py --explain |
| 138 | |
| 139 | # Analyze migration complexity |
| 140 | depyler analyze example.py |
| 141 | ``` |
| 142 | |
| 143 | ### Library Usage |
| 144 | |
| 145 | ```rust |
| 146 | use depyler::{transpile_file, TranspileOptions}; |
| 147 | |
| 148 | fn main() -> Result<(), Box<dyn std::error::Error>> { |
| 149 | let options = TranspileOptions::default() |