Intelligent Python to Rust migration powered by LLMs
py2rs is a desktop application that uses Large Language Models to automatically migrate Python projects to Rust. It analyzes your codebase, detects dependencies, and generates idiomatic Rust code with compile checks and iterative refinement.
- LLM-Powered Migration - Uses AI to understand Python code and generate equivalent Rust
- 300+ Library Mappings - Comprehensive database of Python → Rust crate equivalents
- Automatic Dependency Detection - Identifies external libraries and suggests Rust crates
- Compile Verification - Checks generated code with
cargo checkand iterates on errors - Smart Context - Analyzes project structure and maintains consistency across files
- Multiple LLM Providers - OpenAI, Anthropic, Ollama, llama.cpp, Groq, Azure OpenAI, custom APIs
- Profile Management - Save and load different LLM configurations
- Cost Tracking - Monitor token usage and estimated costs
- Performance Metrics - Track migration speed, success rates, and API usage
- File Selection - Choose specific files to migrate with checkboxes
- Quality Levels - Fast/Balanced/Strict migration modes
- Test Generation - Automatically create unit tests for migrated code
- README Generation - Create documentation for Rust projects
- Multilingual UI - English and Russian interfaces
- Parallel Processing - Configurable thread count for faster migrations
- Dark Mode - Automatic dark theme support
- Stop/Resume - Pause and resume long-running migrations
- Dry-Run Mode - Preview migration without writing files
- .gitignore Support - Respect ignore patterns during file discovery
- Migration History - Track all past migrations with detailed reports
- Export Options - JSON, CSV, and Markdown report formats
- Webhook Notifications - CI/CD integration with custom endpoints
- Drag & Drop - Drop folders directly into the app
- Go to Releases
- Download the latest version for your platform:
- Windows:
py2rs-windows-x64.msi - macOS:
py2rs-macos-universal.dmg - Linux:
py2rs-linux-x64.AppImage
- Windows:
- Install and run the application
- Follow the first-run setup wizard to configure your LLM provider
- Run
setup.bat- installs dependencies and creates icons- If antivirus blocks: run as Administrator or add exception for project folder
- Alternative:
setup-quick.batfor faster debug build
- Run
start.bat- opens the application - Choose your Python project folder
- Configure LLM provider
- Click "Start migration"
# Clone the repository
git clone https://github.com/ThisTakou/Converter-Python-to-Rust.git
cd Converter-Python-to-Rust/py2rs
# Install dependencies
npm install
# Run in development mode
npm run tauri dev
# Build for production
npm run tauri buildOn first launch, configure an LLM provider:
- Provider Type: Choose from OpenAI-compatible, Anthropic, llama.cpp, or Custom API
- Base URL: API endpoint
- API Key: Your API key (optional for local models)
- Model: Model name
Provider: Local / OpenAI-compatible
Base URL: https://api.openai.com/v1
API Key: sk-...
Model: gpt-4-turbo
Also supports:
- Ollama:
http://localhost:11434/v1(no API key) - router.cheap:
https://router.cheap/v1orhttps://direct.router-cheap.com/v1 - LM Studio:
http://localhost:1234/v1 - LocalAI: Your local instance URL
Provider: Anthropic API
API Key: sk-ant-...
Model: claude-3-5-sonnet-20241022
Run llama.cpp with --server flag, then:
Provider: llama.cpp
Base URL: http://localhost:8080
Model: (leave default)
- Select Project: Click "Choose project folder" and select your Python project root
- Project Description: Describe your project in 2-3 sentences (helps AI understand context)
- Review Libraries: Check and edit suggested Rust crates for detected Python dependencies
- Select Files: Use checkboxes to choose which files to migrate (or select all)
- Configure Quality: Choose migration quality level:
- Fast/Lenient: Quick migration, may need manual fixes
- Balanced: Optimal for most projects (default)
- Strict: Maximum quality, slower
- Optional Settings:
- Generate tests for migrated code
- Create README.md for Rust project
- Dry-run mode (preview without writing files)
- Respect .gitignore patterns
- Add Documentation: Click the doc button to add notes for specific modules
- Start Migration: Click "Start migration" and monitor progress
- Review Results: Check generated
*_rs/directory and compilation report
- Save LLM configurations for quick switching
- Load saved profiles with one click
- Manage multiple API keys for different providers
- View all past migrations
- Track success rates and performance metrics
- Export detailed reports (JSON, CSV, Markdown)
- Export migration reports in multiple formats
- Configure webhook notifications for CI/CD
- Integrate with Slack, Discord, or custom endpoints
- Thread Count: Number of parallel LLM requests (1-16, default: 4)
- Dark Theme: Toggle dark/light mode
- Webhook URL: POST migration results to external services
- Language: Switch between English and Russian
py2rs/
├── setup.bat # Windows setup script
├── start.bat # Windows launcher
├── py2rs/
│ ├── ui/ # Frontend (HTML/CSS/JS)
│ │ ├── index.html
│ │ ├── app.js
│ │ ├── style.css
│ │ └── i18n/ # Translations (en, ru)
│ └── src-tauri/ # Rust backend (Tauri)
│ └── src/
│ ├── main.rs # Entry point and Tauri commands
│ ├── migrate.rs # Migration orchestration
│ ├── crate_map.rs # Python → Rust library mappings
│ └── llm.rs # LLM provider integrations
├── examples/ # Example Python projects
│ ├── simple_calculator/
│ ├── flask_api/
│ └── data_processing/
├── .github/ # CI/CD workflows and templates
├── LICENSE # MIT License
├── README.md # This file
├── CONTRIBUTING.md # Contribution guidelines
├── ARCHITECTURE.md # System architecture documentation
├── FAQ.md # Frequently asked questions
└── CHANGELOG.md # Version history
- Project Analysis: Scans Python files, detects imports, builds dependency graph
- Library Detection: Identifies external libraries and suggests Rust crates from 300+ pre-loaded mappings
- File-by-File Migration: Processes files in dependency order
- Sends Python code + context to LLM
- Receives generated Rust code
- Runs
cargo checkwith parallel thread limit - Iterates on compilation errors (up to 5 attempts)
- Interactive Questions: Asks user for clarification when needed
- Final Verification: Builds entire Rust project and generates detailed report
- Clear Description: A good 2-3 sentence project description helps AI understand purpose and constraints
- Document Modules: Add documentation for complex or domain-specific modules
- Choose Right Model:
- Larger models (GPT-4, Claude Opus) - better quality, slower, more expensive
- Smaller models (GPT-3.5, local models) - faster, cheaper, may need more iterations
- Review Crates: AI suggests Rust equivalents, but you can override them
- Manual Review: Always review generated code - AI migration is not perfect
- Start Small: Test with a small module first to verify configuration
- Not 100% Accurate: Generated code may need manual fixes
- Python-Specific Features: Some Python idioms don't translate directly to Rust
- Dynamic Typing: Type inference is best-effort; complex types may need adjustment
- External Dependencies: Quality depends on how well AI knows the suggested crates
- API Costs: Large projects can consume significant API credits
If you see HTTP status client error (403 Forbidden):
- Check API key: Ensure it's valid and has credits
- Verify endpoint: For router.cheap, use OpenAI-compatible provider (not Custom API)
- Try backup URL: Use
https://direct.router-cheap.com/v1if main endpoint fails
If many files fail to compile:
- Reduce thread count (Settings) to avoid overwhelming
cargo check - Add more context in project description
- Document complex modules
- Try a more capable model
- Use stricter quality level
- Increase thread count (Settings)
- Use faster/cheaper models for initial pass
- Use local models (Ollama) for no API latency
- Enable dry-run mode to test before actual migration
- Run
setup.batas Administrator - Add exception for
py2rsfolder - Use
setup-quick.bat(debug build, faster)
- FAQ: Frequently asked questions
- CONTRIBUTING: How to contribute to the project
- ARCHITECTURE: System design and architecture
- CHANGELOG: Version history and roadmap
- Examples: Sample Python projects for testing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
Ways to contribute:
- Report bugs and request features via GitHub Issues
- Submit pull requests with improvements
- Add new Python → Rust library mappings
- Improve documentation and examples
- Share your migration success stories
This project is licensed under the MIT License - see the LICENSE file for details.
- Built with Tauri for cross-platform desktop apps
- Powered by Large Language Models from OpenAI, Anthropic, and the open-source community
- Inspired by the need for safer, faster systems programming
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- FAQ: FAQ.md
Made with care for developers migrating to Rust