RepositoryPython
py2many

py2many/py2many

Transpiler of Python to many other languages

1.4kstars
92forks
119issues
3views

Featured achievements

The project's latest awards

1
TINIX TRENDING·Topic: transpiler

#1 Repository of the week

1
TINIX TRENDING·Topic: nim

#1 Repository of the week

3
TINIX TRENDING·Topic: ast

#3 Repository of the week

py2many: Python to Rust, C++, Go, Zig, Mojo & More - Universal Python Transpiler

Build License

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

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

Proof of Concept: Python to Lean transpilation (only a handful of cases transpile so far).

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:

  • rustfmt for 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 for WASM deployment
  • 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.

Similar Projects

Discover other similar projects and AI models.

RepositoryPython
practical-tutorials/project-based-learning

Curated list of project-based tutorials

290.9k
Nov 30, 2026
Modelfill-mask
jhu-clsp/mmBERT-base

mmBERT: A Modern Multilingual Encoder !License: MIT(https://img.shields.io/badge/License-MIT-yellow.svg)(https://opensource.org/licenses/MIT) !Paper(https://img.shields.io/badge/Paper-Arxiv-red)(https://arxiv.org/abs/2509.06888) !Model(https://img.s...

♥0
348.1k
Oct 7, 2025
RepositoryPython
Significant-Gravitas/AutoGPT

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

188.2k
Nov 29, 2026
RepositoryPython
donnemartin/system-design-primer

Learn how to design large-scale systems. Prep for the system design interview. Includes Anki flashcards.

379.9k
Sep 15, 2026
RepositoryPython
vinta/awesome-python

The definitive list that answers "I want to do X in Python, which tool should I use?"

338.6k
Nov 28, 2026
RepositoryPython
TheAlgorithms/Python

All Algorithms implemented in Python

226.6k
Nov 13, 2026
RepositoryPython
yt-dlp/yt-dlp

A feature-rich command-line audio/video downloader

212.4k
Dec 2, 2026
RepositoryPython
521xueweihan/HelloGitHub

:octocat: 分享 GitHub 上有趣、入门级的开源项目。Share interesting, entry-level open source projects on GitHub.

192.6k
Nov 27, 2026
RepositoryPython
Comfy-Org/ComfyUI

The most powerful and modular diffusion model GUI, api and backend with a graph/nodes interface. The fastest local inference engine in the world.

149.6k
Dec 2, 2026