[go: up one dir, main page]

depyler 1.0.2

A Python-to-Rust transpiler focusing on energy-efficient, safe code generation with progressive verification
Documentation

Depyler

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

Energy-efficient Python-to-Rust transpiler with progressive verification capabilities. Transform Python code into safe, performant Rust while reducing energy consumption by 75-85%. Built with zero tolerance for technical debt and extreme quality standards.

πŸš€ Installation

Install depyler using one of the following methods:

  • From Crates.io (Recommended):

    cargo install depyler
    
  • From Source:

    git clone https://github.com/paiml/depyler
    cd depyler
    cargo build --release
    cargo install --path crates/depyler
    
  • From GitHub Releases: Pre-built binaries are available on the releases page.

Requirements

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

πŸš€ Getting Started

Quick Start

# Transpile a Python file
depyler transpile example.py

# Analyze code complexity before transpilation
depyler analyze example.py

# Run with verification
depyler transpile example.py --verify

# Interactive mode with AI suggestions
depyler interactive example.py --suggest

Using as a Library

Add to your Cargo.toml:

[dependencies]
depyler = "0.3.2"

Basic usage:

use depyler::{transpile_file, TranspileOptions};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let options = TranspileOptions::default()
        .with_verification(true)
        .with_optimization_level(2);
    
    let rust_code = transpile_file("example.py", options)?;
    println!("{}", rust_code);
    
    Ok(())
}

Key Features

πŸ”„ Core Transpilation

  • Python AST to HIR - High-level intermediate representation for safe transformations
  • Type Inference - Smart type analysis with annotation support
  • Memory Safety - Automatic ownership and borrowing inference
  • Direct Rules Engine - Pattern-based Python-to-Rust transformations

⚑ Performance & Efficiency

  • Energy Reduction - 75-85% lower energy consumption vs Python
  • Binary Optimization - Compile with LTO, strip, and panic=abort
  • Zero-Copy Strings - Smart string allocation strategies
  • LLVM Backend - Leverages Rust's optimizing compiler

πŸ›‘οΈ Safety & Verification

  • Property-Based Testing - QuickCheck for semantic equivalence
  • Memory Safety Analysis - Prevents use-after-free and data races
  • Bounds Checking - Automatic insertion where needed
  • Contract Verification - Pre/post condition checking

πŸ€– AI Integration

  • Model Context Protocol - Full MCP v1.0 support
  • Interactive Mode - AI-powered transpilation assistance
  • Annotation Suggestions - Smart optimization hints
  • Complexity Analysis - Migration difficulty assessment

🎯 Supported Python Features

βœ… Production Ready

  • Functions with type annotations
  • Basic types (int, float, str, bool)
  • Collections (List, Dict, Tuple, Set)
  • Control flow (if, while, for, match)
  • List and dict comprehensions
  • Exception handling β†’ Result<T, E>
  • Basic classes and dataclasses
  • Pattern matching (Python 3.10+)

🚧 In Development

  • Async/await support
  • Generator expressions
  • Lambda functions
  • Class inheritance
  • Decorators

❌ Not Supported

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

πŸ“‹ Tool Usage

CLI Interface

# Basic transpilation
depyler transpile input.py              # Creates input.rs
depyler transpile input.py -o output.rs # Custom output
depyler transpile src/ -o rust/         # Directory mode

# Analysis and verification
depyler check input.py                  # Compatibility check
depyler analyze input.py                # Complexity metrics
depyler verify output.rs                # Verify generated code
depyler inspect input.py --repr ast     # View AST/HIR

# Interactive features
depyler interactive input.py            # Interactive session
depyler interactive input.py --suggest  # With AI suggestions

# Quality enforcement
depyler transpile input.py --verify --strict  # Full verification
depyler quality-check input.py               # PMAT scoring

MCP Integration

# Use with Claude or other MCP-compatible AI assistants
depyler serve --mcp

# Available MCP tools:
# - transpile_python: Convert Python to Rust
# - analyze_complexity: Code complexity analysis
# - verify_transpilation: Verify semantic equivalence
# - suggest_annotations: Optimization hints

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Python AST    │────▢│      HIR        │────▢│   Rust AST      β”‚
β”‚  (rustpython)   β”‚     β”‚  (Intermediate) β”‚     β”‚     (syn)       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚                       β”‚                        β”‚
         β–Ό                       β–Ό                        β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Type Inference  β”‚     β”‚  Optimizations  β”‚     β”‚ Code Generation β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“Š Quality Standards

Following the Toyota Way principles:

θ‡ͺεƒεŒ– (Jidoka) - Build Quality In

  • Never ship incomplete transpilation
  • All generated code must compile
  • Verification-first development

ηΎεœ°ηΎη‰© (Genchi Genbutsu) - Direct Observation

  • Test against real Python codebases
  • Profile actual compilation times
  • Debug at the Rust level

ζ”Ήε–„ (Kaizen) - Continuous Improvement

  • Incremental verification levels
  • Performance baselines
  • Code quality targets

πŸ§ͺ Testing

# Run all tests
cargo test --workspace

# Run with coverage
cargo tarpaulin --out Html

# Run property tests
cargo test --features quickcheck

# Run benchmarks
cargo bench

# Run specific test suites
cargo test -p depyler-core        # Core transpilation
cargo test -p depyler-verify      # Verification
cargo test -p depyler-mcp         # MCP integration

🀝 Contributing

We welcome contributions! Please follow our quality standards:

  1. Write tests first - TDD is mandatory
  2. Maintain coverage - 85%+ for all new code
  3. Zero warnings - cargo clippy -- -D warnings
  4. Format code - cargo fmt
  5. Document changes - Update relevant docs

See CONTRIBUTING.md for detailed guidelines.

πŸ“š Documentation

🚦 Roadmap

Current: v1.0 - Core Transpilation βœ…

  • Safe subset transpilation
  • PMAT quality metrics
  • Property-based testing
  • Basic MCP integration

Next: v1.1 - Enhanced Type System

  • Lifetime inference
  • Dataclass support
  • Improved string handling
  • Contract verification

Future: v1.2 - Advanced Patterns

  • Async/await support
  • Iterator protocol
  • Context managers
  • Exception patterns

See ROADMAP.md for detailed plans.

πŸ“„ License

Licensed under the MIT License - see LICENSE for details.


Built with extreme quality standards by the Depyler team