百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
D

depyler

> 编程语言
开源

将 Python 编译为 Rust,帮助从 Python 转向节能、安全的 Rust 代码

357 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

将 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.

Table of Contents

  • What's New in v4.1.1
  • Features
  • Installation
  • Quick Start
  • Usage
  • Supported Python Features
  • Stdlib Module Support
  • Architecture
  • Documentation
  • Quality Metrics
  • Contributing
  • License

What's New in v4.1.1

  • str(dict.get(key, default)) fix: No longer generates spurious .unwrap() calls
  • 25+ Python module mappings: tempfile, datetime, os, shutil, glob, and more
  • E0433 import resolution: Improved handling of unresolved imports
  • [profile.test] opt-level=1: Faster test execution

Multi-Corpus Convergence (v3.25.0+)

All 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%

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
  • 80%+ Single-Shot Compile Rate — Most Python files compile on first transpilation attempt

Installation

bash
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:

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

# Run the compiled binary
./script

Transpile to Rust

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

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

Example

Input (fibonacci.py):

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

Supported Python Features

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.

Stdlib Module Support

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.

Architecture

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

Documentation

  • API Documentation
  • MCP Quickstart
  • Agent Mode Guide
  • Developer Prompts
  • Changelog
  • TDD Book
  • Coursera Hugging Face AI Development Specialization - Build Production AI systems with Hugging Face in Pure Rust

Quality Metrics

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:

bash
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.

MSRV

Minimum Supported Rust Version: 1.83

Cookbook

See depyler-cookbook for examples and recipes.

License

Licensed under MIT License. See LICENSE for details.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rustconversionmcppaiml-active-toolpaiml-transpiler

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言