depyler 2.2.1

A Python-to-Rust transpiler focusing on energy-efficient, safe code generation with progressive verification
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
# Depyler

[![Crates.io](https://img.shields.io/crates/v/depyler.svg)](https://crates.io/crates/depyler)
[![Documentation](https://docs.rs/depyler/badge.svg)](https://docs.rs/depyler)
[![CI](https://github.com/paiml/depyler/actions/workflows/ci.yml/badge.svg)](https://github.com/paiml/depyler/actions/workflows/ci.yml)
[![Coverage](https://img.shields.io/badge/coverage-85%25+-brightgreen.svg)](https://codecov.io/gh/paiml/depyler)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Apache License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![Rust 1.83+](https://img.shields.io/badge/rust-1.83+-orange.svg)](https://www.rust-lang.org)
[![MCP Compatible](https://img.shields.io/badge/MCP-Compatible-green)](https://modelcontextprotocol.io)
[![Downloads](https://img.shields.io/crates/d/depyler)](https://crates.io/crates/depyler)

**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 following the Toyota Way.

> **Enterprise Testing Excellence**: v2.2.0 delivers enterprise-grade testing
> infrastructure with 300+ tests across property-based, mutation, fuzzing, and
> coverage testing frameworks. Features comprehensive CI/CD integration,
> automated quality gates, and cross-platform testing matrix. Maintains zero
> defects policy with formal verification readiness and ownership inference.

## ๐Ÿš€ Installation

Install `depyler` using one of the following methods:

- **From Crates.io (Recommended):**
  ```bash
  cargo install depyler
  ```

- **From Source:**
  ```bash
  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]https://github.com/paiml/depyler/releases.

### Requirements

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

## ๐Ÿš€ Getting Started

### Quick Start

```bash
# Transpile a Python file
depyler transpile example.py

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

# Analyze code complexity before transpilation
depyler analyze example.py

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

# Check transpilation compatibility
depyler check example.py

# Inspect AST/HIR representations
depyler inspect example.py --repr hir

# Start Language Server for IDE integration
depyler lsp

# Profile Python code for performance analysis
depyler profile example.py --flamegraph

# Generate documentation from Python code
depyler docs example.py --output ./docs
```

### Using as a Library

Add to your `Cargo.toml`:

```toml
[dependencies]
depyler = "2.2.0"
```

Basic usage:

```rust
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
- **String Optimization** - Interning for frequently used literals, Cow<str> for
  flexible ownership

### โšก 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 with Cow<str>
- **LLVM Backend** - Leverages Rust's optimizing compiler
- **String Interning** - Automatic interning for strings used >3 times

### ๐Ÿ›ก๏ธ 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
- **Formal Verification Ready** - Structured for future SMT integration

### ๐Ÿค– 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

### ๐Ÿ› ๏ธ Developer Tools

- **Language Server Protocol** - VSCode, Neovim, and other IDE support
- **Debugging Support** - Source mapping and debugger integration
- **Performance Profiling** - Hot path detection and optimization
- **Documentation Generation** - Auto-generate API docs from Python

### ๐ŸŽฏ Supported Python Features

#### โœ… Production Ready

- Functions with type annotations
- Basic types (`int`, `float`, `str`, `bool`)
- Collections (`List`, `Dict`, `Tuple`, `Set`, `FrozenSet`)
- Control flow (`if`, `while`, `for`, `break`, `continue`)
- List, dict, and set comprehensions
- Exception handling โ†’ `Result<T, E>`
- Classes with methods, properties, dataclasses
- Static methods and class methods
- Basic async/await support
- Lambda functions
- Power operator (**) and floor division (//)
- String optimization (interning, Cow<str> support)
- Protocol to Trait mapping
- Const generic array inference
- With statements (context managers)
- Iterator protocol (**iter**, **next**)

#### ๐Ÿšง In Development

- Full async/await (async iterators, generators)
- Generator expressions with yield
- Advanced decorators
- Class inheritance
- Match/case statements (Python 3.10+)
- Package imports and relative imports

#### โŒ Not Supported

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

## ๐Ÿ“‹ Tool Usage

### CLI Interface

```bash
# 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          # With verification
depyler quality-check input.py               # Toyota Way scoring

# Developer tools
depyler lsp                                  # Start Language Server
depyler debug --tips                         # Debugging guide
depyler profile input.py                     # Performance profiling
depyler docs input.py                        # Generate documentation
```

### MCP Integration

#### Using with Claude Code

```bash
# Add to Claude Code
claude mcp add depyler ~/.local/bin/depyler
```

#### MCP Server Mode

```bash
# Start MCP server
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
```

### HTTP API

```bash
# Start HTTP server
depyler serve --port 8080 --cors

# API endpoints
curl "http://localhost:8080/health"
curl "http://localhost:8080/api/v1/transpile" \
  -H "Content-Type: application/json" \
  -d '{"code":"def add(a: int, b: int) -> int: return a + b"}'
```

## ๐Ÿ—๏ธ Architecture

```
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   Python AST    โ”‚โ”€โ”€โ”€โ”€โ–ถโ”‚      HIR        โ”‚โ”€โ”€โ”€โ”€โ–ถโ”‚   Rust AST      โ”‚
โ”‚  (rustpython)   โ”‚     โ”‚  (Intermediate) โ”‚     โ”‚     (syn)       โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚                       โ”‚                        โ”‚
         โ–ผ                       โ–ผ                        โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Type Inference  โ”‚     โ”‚  Optimizations  โ”‚     โ”‚ Code Generation โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
```

## ๐Ÿšฆ CI/CD Integration

### GitHub Actions Example

```yaml
name: Transpile and Verify
on: [push, pull_request]

jobs:
  quality:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: dtolnay/rust-toolchain@stable

      - name: Install depyler
        run: cargo install depyler

      - name: Check Python compatibility
        run: depyler check src/**/*.py

      - name: Transpile to Rust
        run: depyler transpile src/ -o rust/ --verify

      - name: Run quality checks
        run: depyler quality-check src/**/*.py --strict
```

## Toyota Way Quality Standards

This project exemplifies the Toyota Way philosophy through disciplined quality
practices:

### ่‡ชๅƒๅŒ– (Jidoka) - Build Quality In

- **ZERO SATD**: No TODO, FIXME, HACK, or placeholder implementations
- **ZERO Incomplete**: All features fully implemented with unreachable!()
  removed
- **ZERO High Complexity**: No function exceeds cyclomatic complexity of 20
- **100% Verification**: All generated code must compile and pass tests

### ็พๅœฐ็พ็‰ฉ (Genchi Genbutsu) - Go and See

- **Real-World Testing**: Validated against actual Python codebases
- **Performance Profiling**: Energy consumption measured on real hardware
- **Direct Debugging**: Debug at the generated Rust level, not just HIR

### ๆ”นๅ–„ (Kaizen) - Continuous Improvement

- **v1.0.1**: Fixed all SATD markers and incomplete implementations
- **v1.0.2**: Enhanced string optimization with interning and Cow<str>
- **Next**: Lifetime analysis enhancements for better borrowing inference

## ๐Ÿงช Testing

```bash
# 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
```

## Recent Updates

### ๐Ÿงช v2.2.0 - Enterprise Testing Infrastructure

- **Advanced Testing Frameworks**: 300+ tests across multiple paradigms
  - Property-based testing with custom generators
  - Mutation testing for code robustness
  - Multi-strategy fuzzing (security, unicode, performance)
  - Specialized coverage testing with error path analysis
- **Quality Automation**: Continuous monitoring and metrics
  - PMAT metrics dashboard with TDG scoring
  - Automated quality gates and thresholds
  - Performance regression detection
- **CI/CD Integration**: Comprehensive GitHub Actions workflows
  - Cross-platform testing matrix (Linux, macOS, Windows)
  - Automated release workflows
  - Quality gate enforcement

### ๐Ÿ› ๏ธ v2.1.0 - Developer Tooling Suite

- **IDE Integration (LSP)**: Full Language Server Protocol support
  - Symbol navigation, hover info, completions, diagnostics
  - Go-to-definition and find-references
- **Debugging Support**: Source mapping and debugger integration
  - Debug levels: None, Basic (line mapping), Full (variable state)
  - GDB/LLDB script generation
- **Performance Profiling**: Analyze transpiled code performance
  - Hot path detection and flamegraph generation
  - Performance predictions and optimization hints
- **Documentation Generation**: Auto-generate docs from Python
  - API references, usage guides, migration notes
  - Markdown and HTML output formats

### ๐Ÿš€ v2.0.0 - Production Ready

- **Optimization Framework**: Dead code elimination, constant propagation
- **Enhanced Diagnostics**: Context-aware errors with suggestions
- **Migration Analysis**: Python-to-Rust idiom recommendations
- **Performance Warnings**: Detect O(nยฒ) algorithms and inefficiencies
- **Type Inference**: Intelligent parameter and return type suggestions
- **Function Inlining**: Smart inlining with cost-benefit analysis

### ๐ŸŽฏ v1.x Series - Core Features

- **v1.6.0**: Extended standard library mappings (20+ modules)
- **v1.5.0**: Basic module system and imports
- **v1.4.0**: Async/await support
- **v1.3.0**: Advanced type features (with statements, iterators)
- **v1.2.0**: Full OOP support (classes, methods, properties)
- **v1.1.0**: Core language completeness (operators, collections)

## ๐Ÿค 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](CONTRIBUTING.md) for detailed guidelines.

## ๐Ÿ“š Documentation

- **[API Documentation]https://docs.rs/depyler** - Complete Rust API reference
- **[User Guide]docs/user-guide.md** - Getting started tutorial
- **[Migration Guide]docs/migration-guide.md** - Python to Rust transition
- **[Python-Rust Spec]docs/python-to-rust-spec.md** - Language mapping
- **[Safety Guarantees]docs/safety-guarantees.md** - Memory safety analysis
- **[MCP Integration]docs/mcp-integration.md** - AI assistant integration

## ๐Ÿšฆ Roadmap

### โœ… v2.2 - Enterprise Testing (Released)

- Property-based testing framework
- Mutation testing infrastructure  
- Security-focused fuzzing
- CI/CD integration with quality gates

### โœ… v2.1 - Developer Experience (Released)

- Complete IDE integration with LSP
- Comprehensive debugging support
- Performance profiling tools
- Documentation generation

### โœ… v2.0 - Production Ready (Released)

- Advanced optimization passes
- Enhanced error reporting
- Migration suggestions
- Performance analysis

### โœ… v1.x - Feature Complete (Released)

- Core language support
- Object-oriented programming
- Type system enhancements
- Async/await basics
- Module system
- Standard library mappings

### ๐Ÿ”ฎ v3.0 - Advanced Features (Future)

- Full generator support with yield
- Advanced decorator patterns
- Complete async ecosystem
- Package management integration

See [ROADMAP.md](ROADMAP.md) for detailed plans.

## ๐Ÿ“„ License

Licensed under either of:

- Apache License, Version 2.0 ([LICENSE-APACHE]LICENSE-APACHE)
- MIT license ([LICENSE-MIT]LICENSE-MIT)

at your option.

---

**Built with extreme quality standards by the Depyler team**