MCP Hub
Back to servers

Depyler

Energy-efficient Python-to-Rust transpiler with progressive verification, enabling AI assistants to convert Python code to safe, performant Rust while reducing energy consumption by 75-85%.

Stars
295
Forks
12
Tools
3
Updated
Jan 7, 2026
Validated
Jan 9, 2026
depyler

depyler

A Python-to-Rust transpiler with semantic verification and memory safety analysis.

Crates.io Documentation CI License


Depyler translates annotated Python code into idiomatic Rust, preserving program semantics while providing compile-time safety guarantees. Part of the PAIML Stack.

Table of Contents

Features

  • Type-Directed Transpilation — Uses Python type annotations to generate appropriate Rust types
  • Memory Safety Analysis — Infers ownership and borrowing patterns automatically
  • Semantic Verification — Property-based testing to verify behavioral equivalence
  • Single-Command Compilation — Compile Python to native binaries with depyler compile
  • 27 Stdlib Modules — Production-ready support for common Python standard library modules

Installation

cargo install depyler

Requirements

  • Rust 1.83.0 or later
  • Python 3.8+ (for test validation)

Quick Start

Compile to Binary

The fastest way to use Depyler:

# Compile Python to a standalone binary
depyler compile script.py

# Run the compiled binary
./script

Transpile to Rust

# Transpile a Python file to Rust
depyler transpile example.py

# Transpile with semantic verification
depyler transpile example.py --verify

Example

Input (fibonacci.py):

def fibonacci(n: int) -> int:
    if n <= 1:
        return n
    return fibonacci(n - 1) + fibonacci(n - 2)

Output (fibonacci.rs):

fn fibonacci(n: i32) -> i32 {
    if n <= 1 {
        return n;
    }
    fibonacci(n - 1) + fibonacci(n - 2)
}

Usage

Compilation Options

# Compile with custom output name
depyler compile script.py -o my_app

# Debug build (faster compilation)
depyler compile script.py --profile debug

# Release build (optimized, default)
depyler compile script.py --profile release

Transpilation Options

# Show transpilation trace
depyler transpile example.py --trace

# Explain transformation decisions
depyler transpile example.py --explain

# Analyze migration complexity
depyler analyze example.py

Library Usage

use depyler::{transpile_file, TranspileOptions};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let options = TranspileOptions::default()
        .with_verification(true);

    let rust_code = transpile_file("example.py", options)?;
    println!("{}", rust_code);

    Ok(())
}

Supported Python Features

FeatureStatus
Functions with type annotationsSupported
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 expressionsSupported
Exception handling (→ Result<T, E>)Supported
Classes and methodsSupported
Async/awaitSupported
Context managersSupported

Not Supported: Dynamic features (eval, exec), runtime reflection, multiple inheritance, monkey patching.

Stdlib Module Support

27 modules validated with 151 tests passing (100% coverage).

CategoryModules
Serializationjson, struct, base64, csv
Date/Timedatetime, calendar, time
Cryptographyhashlib, secrets
Texttextwrap, re, string
Mathmath, decimal, fractions, statistics
File Systemos, pathlib, io
Data Structurescollections, copy, memoryview, array
Functionalitertools, functools
Randomrandom
Systemsys

See validation report for details.

Architecture

Python AST → HIR → Type Inference → Rust AST → Code Generation
ComponentDescription
ParserRustPython AST parser
HIRHigh-level intermediate representation
Type SystemConservative type inference with annotation support
VerificationProperty-based testing for semantic equivalence
CodegenRust code generation via syn/quote

Documentation

Quality Metrics

MetricValue
Line Coverage87.85%
Function Coverage92.85%
Total Tests14,000+
Mutation Kill Rate75%+

Run coverage locally:

cargo llvm-cov nextest --workspace --lib --summary-only

Contributing

Contributions welcome! Please follow the quality standards:

  1. Write tests first (TDD)
  2. Maintain 80%+ coverage for new code
  3. Pass all clippy checks: cargo clippy -- -D warnings
  4. Format code: cargo fmt

See CONTRIBUTING.md for details.

License

Licensed under MIT License. See LICENSE for details.

Reviews

No reviews yet

Sign in to write a review