Skip to main content

Python to CLike language transpiler.

Project description

py2many: Python to many CLike languages transpiler

Build License


Python is popular, easy to program in, but has poor runtime performance. We can fix that by transpiling a subset of the language into a more performant, statically typed language.

A second benefit is security. Writing security sensitive code in a low level language like C is error prone and could lead to privilege escalation. Specialized languages such as wuffs exist to address this use case. py2many can be a more general purpose solution to the problem where you can verify the source via unit tests before you transpile.

A third potential use case is to accelerate python code by transpiling it into an extension

Swift and Kotlin dominate the mobile app development workflow. However, there is no one solution that works well for lower level libraries where there is desire to share code between platforms. Kotlin Mobile Multiplatform (KMM) is a player in this place, but it hasn't really caught on. py2many provides an alternative.

Lastly, it's a great educational tool to learn a new language by implementing a backend for your favorite language.


Rust is the language where the focus of development has been.

C++14 is historically the first language to be supported. C++17 is now required for some features.

Preliminary support exists for Julia, Kotlin, Nim, Go and Dart.

py2many can also emit Python 3 code that includes inferred type annotations, and revisions to the syntax intended to simplify parsing of the code.


Based on Julian Konchunas' pyrs

Based on Lukas Martinelli Py14 ( and Py14/python-3 ( branch by Valentin Lorentz.


Original Python version.

def fib(i: int) -> int:
    if i == 0 or i == 1:
        return 1
    return fib(i - 1) + fib(i - 2)

Transpiled Rust code:

fn fib(i: i32) -> i32 {
    if i == 0 || i == 1 {
        return 1;
    return (fib((i - 1)) + fib((i - 2)));

Transpiled code for other languages: (fib*)

Trying it out


  • Python 3.8+

Local installation:

./ install --user  # installs to $HOME/.local


sudo ./ install  # installs systemwide

Add the py2many script to your $PATH and run:


py2many --cpp=1 tests/cases/
py2many --rust=1 tests/cases/
py2many --julia=1 tests/cases/
py2many --kotlin=1 tests/cases/
py2many --nim=1 tests/cases/
py2many --dart=1 tests/cases/
py2many --go=1 tests/cases/


clang tests/cases/fib.cpp
rustc tests/cases/

Many of the transpilers rely on a language specific formatter to parse the output and reformat it. Typically this is the most prominent formatter for the language, such as rustfmt for Rust.

Most of the transpilers also rely on external libraries to provide bridges from Python constructs to the target language.

The steps to install these external libraries can be found in .github/workflows/main.yml.


See for how to test your changes and contribute to this project.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py2many-0.4.tar.gz (231.8 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page