[go: up one dir, main page]

depyler 3.4.1

A Python-to-Rust transpiler focusing on energy-efficient, safe code generation with progressive verification
docs.rs failed to build depyler-3.4.1
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build: depyler-2.2.2

Depyler

Crates.io Documentation CI Coverage License: MIT Apache License Rust 1.83+

A Python-to-Rust transpiler with semantic verification and memory safety analysis. Depyler translates annotated Python code into idiomatic Rust, preserving program semantics while providing compile-time safety guarantees.

Installation

cargo install depyler

Requirements

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

Usage

Basic Transpilation

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

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

# Analyze migration complexity
depyler analyze example.py

Example

Input (example.py):

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

Output (example.rs):

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

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(())
}

Features

Core Capabilities

  • Type-directed transpilation: Uses Python type annotations to generate appropriate Rust types
  • Memory safety analysis: Infers ownership and borrowing patterns
  • Semantic verification: Property-based testing to verify behavioral equivalence
  • Multiple backends: Generate Rust or Ruchy script code

Supported Python Features

Currently Supported:

  • Functions with type annotations
  • Basic types (int, float, str, bool)
  • Collections (List, Dict, Tuple, Set)
  • Control flow (if, while, for, match)
  • List/dict/set comprehensions
  • Exception handling (mapped to Result<T, E>)
  • Classes and methods
  • Async/await (basic)
  • Context managers (with statements)
  • Iterators

Not Supported:

  • Dynamic features (eval, exec)
  • Runtime reflection
  • Multiple inheritance
  • Monkey patching

See documentation for complete feature list.

MCP Server

Depyler is available as an MCP (Model Context Protocol) server for AI assistants like Claude Code.

Installation

Install via the MCP Registry:

# Install the server
cargo install depyler

# Verify installation
depyler --version

Claude Desktop Setup

Add to your Claude Desktop config (~/.config/Claude/claude_desktop_config.json):

{
  "mcpServers": {
    "depyler": {
      "command": "depyler",
      "args": ["agent", "start", "--foreground"]
    }
  }
}

Available MCP Tools

  • transpile_python - Convert Python code to Rust
  • analyze_migration_complexity - Analyze migration effort and complexity
  • verify_transpilation - Verify semantic equivalence between Python and Rust
  • pmat_quality_check - Run code quality analysis

Documentation

Registry

View Depyler in the MCP Registry

Published: io.github.noahgift/depyler-mcp v3.4.0

Architecture

Depyler uses a multi-stage compilation pipeline:

Python AST → HIR → Type Inference → Rust AST → Code Generation

Key components:

  • 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

Quality Standards

This project follows strict quality standards:

  • Test coverage: 70%+ (596 passing tests)
  • Max cyclomatic complexity: ≤20
  • Zero clippy warnings (-D warnings)
  • Zero self-admitted technical debt (SATD)
  • TDG grade: A+ (99.1/100)

Development

Running Tests

# Run all tests
cargo test --workspace

# Run with coverage
cargo llvm-cov --html --open

# Run benchmarks
cargo bench

Quality Checks

# Lint
cargo clippy --all-targets --all-features -- -D warnings

# Format
cargo fmt --all

# Quality gates
pmat quality-gate

Documentation

License

Licensed under either of:

at your option.

Contributing

Contributions are welcome. Please follow the quality standards:

  1. Write tests first (TDD)
  2. Maintain 80%+ coverage for new code
  3. Pass all clippy checks
  4. Update documentation

See CONTRIBUTING.md for details.