py2many: Python to Rust, C++, Go, Zig, Mojo & More - Universal Python Transpiler
Convert Python code to Rust, C++, Go, Zig, Julia, Nim, Dart, and other languages automatically
py2many is a powerful Python transpiler that converts Python source code into multiple statically-typed programming languages. Transform your Python code to Rust for performance, C++ for systems programming, Go for concurrency, or Kotlin for mobile development.
Why Convert Python to Other Languages
Performance: Python is popular and easy to program in, but has poor runtime performance. Transpiling Python to Rust, C++, or Go can dramatically improve execution speed while maintaining the development experience of Python.
Security: Writing security-sensitive code in low-level languages like C is error-prone and could lead to privilege escalation. With py2many, you can write secure code in Python, verify it with unit tests, then transpile to a safer systems language like Rust.
Cross-platform Development: Accelerate Python code by transpiling it into native extensions or standalone applications.
Mobile & Systems Programming: While Swift and Kotlin dominate mobile app development, there's no universal solution for sharing lower-level library code between platforms. py2many provides an alternative to Kotlin Mobile Multiplatform (KMM) by letting you write once in Python and deploy to multiple targets.
Learning Tool: It's an excellent educational tool for learning new programming languages by comparing Python implementations with their transpiled equivalents.
Supported Languages & Status
See LANGUAGES.md for current status of each language.
Primary Focus: Python to Rust conversion with the most mature feature set and active development.
Production Ready: Python to C++ transpilation (C++14 historically supported, C++17+ required for advanced features).
Beta Support: Python to Lean, Python to Julia, Python to Kotlin, Python to Nim, Python to Go, Python to Dart, Python to V, and Python to D transpilation.
Experimental Support: Python to Zig and Python to Mojo transpilation (early stage, limited feature coverage).
Type Inference: py2many can also emit enhanced Python 3 code with inferred type annotations and syntax improvements for better code analysis.
Python to Rust Example
See how py2many converts Python code to idiomatic Rust:
Original Python code:
def fib(i: int) -> int:
if i == 0 or i == 1:
return 1
return fib(i - 1) + fib(i - 2)
# Demonstrate overflow handling
def add(i: i32, j: i32):
return i + j
Transpiled Rust code:
fn fib(i: i32) -> i32 {
if i == 0 || i == 1 {
return 1;
}
return (fib((i - 1)) + fib((i - 2)));
}
// return type is i64
pub fn add(i: i32, j: i32) -> i64 {
return ((i as i64) + (j as i64)) as i64;
}
More Examples: View transpiled code for all supported languages at: https://github.com/py2many/py2many/tree/main/tests/expected (fib*)
Quick Start: Convert Python to Rust, C++, Go & More
Requirements:
- Python 3.8+
Installation:
uv pip install py2many
You can also run py2many without a separate install using uvx:
uvx py2many --mylang test.py
Usage Examples:
To transpile a Python file, run py2many with the target language flag:
# General form
uvx py2many --mylang test.py
# Python to Rust
py2many --rust tests/cases/fib.py
# Python to C++
py2many --cpp tests/cases/fib.py
# Python to Go
py2many --go tests/cases/fib.py
# Python to Kotlin
py2many --kotlin tests/cases/fib.py
# Python to Julia
py2many --julia tests/cases/fib.py
# Python to Nim
py2many --nim tests/cases/fib.py
# Python to Dart
py2many --dart tests/cases/fib.py
# Python to D
py2many --dlang tests/cases/fib.py
# Python to Lean (proof of concept)
py2many --lean tests/cases/hello_world.py
Compiling Transpiled Code:
# Compile C++
clang tests/expected/fib.cpp
# Run Rust
./scripts/rust-runner.sh run tests/expected/fib.rs
# Run D
ldmd2 -run tests/cases/fib.d
Language-Specific Tools:
py2many integrates with language-specific formatters and tools:
rustfmtfor Rust code formatting- Language-specific standard libraries and external dependencies
For detailed setup instructions for each target language, see .github/workflows/main.yml.
Key Features
- Multi-Language Support: Convert Python to 8+ programming languages
- Type Inference: Automatically infer and convert Python types to target language types
- Performance Optimization: Generate optimized code for systems programming languages
- Cross-Platform: Works on Linux, macOS, and Windows
- Open Source: MIT licensed with active community development
- Educational: Compare Python implementations with transpiled code to learn new languages
Use Cases
- Performance-Critical Applications: Convert Python algorithms to Rust or C++ for speed
- Systems Programming: Transform Python prototypes to systems languages
- Mobile Development: Convert Python logic to Kotlin for Android development
- WebAssembly: Transpile Python to Rust or Zig for WASM deployment
- Web: Transpile Python to Dart which can generate JavaScript
- Embedded Systems: Convert Python code to C++ or Rust for resource-constrained environments
- Cross-Platform Libraries: Write once in Python, deploy to multiple language ecosystems
Project History
Based on Julian Konchunas' pyrs.
Based on Lukas Martinelli Py14 and Py14/python-3 branch by Valentin Lorentz.
Contributing
See CONTRIBUTING.md for how to test your changes and contribute to this project.
Metadata
Release files for py2many 0.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| py2many-0.9.tar.gz | 363.4 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| py2many-0.9-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 599.4 kB
Release files / py2many-0.9.tar.gz
| Download URL | py2many-0.9.tar.gz |
|---|---|
| Size | 363.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e98b39301e431a20e62c2d22ed3aee21654e80ae618fcc4239520410776038be
|
|
BLAKE2b-256 checksum How to use checksums |
a9f29c12a5daacad5ba111f7197403c3b3ea484b8b9c53f0f0e571c04a0b66a6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.3
|
Release files / py2many-0.9-py3-none-any.whl
| Download URL | py2many-0.9-py3-none-any.whl |
|---|---|
| Size | 236.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b3e46b159cc2e271f094cd66ded536708e5603d77fa1d05d4d76024298ed068f
|
|
BLAKE2b-256 checksum How to use checksums |
dff47e86c3ff0c073c89ad0283dde9f0017aaf90b6044ce79d9590465c3f760c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.3
|
Security for py2many 0.9
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.