将 Python 编译为 Rust,帮助从 Python 转向节能、安全的 Rust 代码
Depyler translates annotated Python code into idiomatic Rust, preserving program semantics while providing compile-time safety guarantees. Part of the PAIML Stack.
str(dict.get(key, default)) fix: No longer generates spurious .unwrap() callstempfile, datetime, os, shutil, glob, and more[profile.test] opt-level=1: Faster test executionAll three external corpus targets met:
| Corpus | Compile Rate | Target |
|---|---|---|
| Tier 1 (stdlib) | 92.7% (38/41) | 80% |
| Tier 2 (typed-cli) | 62.5% (10/16) | 60% |
| Tier 5 (algorithms) | 47.5% (48/101) | 40% |
| Internal examples | 80% (256/320) | 80% |
depyler compilecargo install depylerThe fastest way to use Depyler:
# Compile Python to a standalone binary
depyler compile script.py
# Run the compiled binary
./script# Transpile a Python file to Rust
depyler transpile example.py
# Transpile with semantic verification
depyler transpile example.py --verifyInput (fibonacci.py):
def fibonacci(n: int) -> int:
if n i32 {
if n Result> {
let options = TranspileOptions::default()
.with_verification(true);
let rust_code = transpile_file("example.py", options)?;
println!("{}", rust_code);
Ok(())
}| Feature | Status |
|---|---|
| Functions with type annotations | Supported |
| Basic types (int, float, str, bool) | Supported |
| Collections (List, Dict, Tuple, Set) | Supported |
| Control flow (if, while, for, match) | Supported |
| Comprehensions (list, dict, set) | Supported |
| Generator expressions | Supported |
| Exception handling (→ Result) | Supported |
| Classes and methods | Supported |
| Async/await | Supported |
| Context managers | Supported |
Not Supported: Dynamic features (eval, exec), runtime reflection, multiple inheritance, monkey patching.
27 modules validated with 151 tests passing (100% coverage).
| Category | Modules |
|---|---|
| Serialization | json, struct, base64, csv |
| Date/Time | datetime, calendar, time |
| Cryptography | hashlib, secrets |
| Text | textwrap, re, string |
| Math | math, decimal, fractions, statistics |
| File System | os, pathlib, io |
| Data Structures | collections, copy, memoryview, array |
| Functional | itertools, functools |
| Random | random |
| System | sys |
See validation report for details.
Python AST → HIR → Type Inference → Rust AST → Code Generation| Component | Description |
|---|---|
| Parser | RustPython AST parser |
| HIR | High-level intermediate representation |
| Type System | Conservative type inference with annotation support |
| Verification | Property-based testing for semantic equivalence |
| Codegen | Rust code generation via syn/quote |
| Metric | Value |
|---|---|
| Single-Shot Compile Rate | 80% (256/320 examples) |
| Line Coverage | 87.85% |
| Function Coverage | 92.85% |
| Total Tests | 23,335+ |
| Mutation Kill Rate | 75%+ |
Run coverage locally:
cargo llvm-cov nextest --workspace --lib --summary-onlyContributions welcome! Please follow the quality standards:
cargo clippy -- -D warningscargo fmtSee CONTRIBUTING.md for details.
Minimum Supported Rust Version: 1.83
See depyler-cookbook for examples and recipes.
Licensed under MIT License. See LICENSE for details.
暂无开放 Issues,或尚未同步最近议题。