Skip to content
/ Pytra Public

Ultimate transpiler: converts Python to C++, Rust, C#, JavaScript, TypeScript, Go, Java, Swift, Kotlin, Ruby, Lua, Scala3, PHP, and Nim.

License

Notifications You must be signed in to change notification settings

yaneurao/Pytra

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2,466 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Read in Japanese

Pytra Code Alchemist

Pytra

Python (subset) is the source language for Pytra, which transpiles code into multiple target languages.

Read the Docs

C++ Rust C# JS TS Go Java
Swift Kotlin Ruby Lua Scala3 PHP Nim

Latest News

2026-03-02 | v0.6.0 Released
Version 0.6.0 was released, adding Scala as a supported target language.

2026-03-01 | v0.5.0 Released
Version 0.5.0 was released, adding Lua as a supported target language.

2026-02-28 | v0.4.0 Released
Version 0.4.0 was released, adding Ruby as a supported target language.

Features

Pytra's features

  • Python to multi-language transpiler

    • Supports conversion to C++, C#, Rust, JavaScript, TypeScript, Go, Java, Swift, Kotlin, Ruby, Lua, Scala3, and PHP.
    • Converts code to output in a form extremely close to the original source.
  • Write Python code that targets C++-level output quality

    • int defaults to 64-bit signed integer.
    • No dynamic typing.
  • Simple language model

    • Basically a subset of Python.
    • Can be developed with existing tools such as VS Code.
    • Drops multiple inheritance and keeps only single inheritance.
  • High extensibility

    • The transpiler core is implemented in Python, making extension and customization easy.
    • The transpiler's own source code can be transpiled into other languages by this transpiler, enabling self-hosting.

We also prioritize practical operational benefits.

WARNING: This project is still under active development and may be far from production-ready. Review sample code first and use at your own risk.

WARNING: Do not expect entire Python applications to be portable as-is. A realistic expectation is: if the core logic you wrote in Python transpiles well, that is a good outcome.

Runtime Performance Comparison

Execution times for sample programs written in Python and their transpiled versions (unit: seconds). In the table, Python is the original code and PyPy is for reference.

No. Workload Python PyPy C++ Rust C# JS TS Go Java Swift Kotlin Ruby Lua Scala3 PHP
01 Mandelbrot set (PNG) 18.647 1.091 0.790 0.781 0.383 0.768 0.806 0.753 0.756 0.760 0.756 18.955 5.500 2.221 6.159
02 Simple sphere ray tracer (PNG) 6.890 0.529 0.202 0.165 0.918 0.277 0.288 0.256 0.260 0.289 0.258 11.146 3.049 15.765 2.372
03 Julia set (PNG) 22.770 1.959 0.861 0.823 1.468 1.210 1.127 1.126 1.136 1.125 1.151 37.170 8.162 7.935 5.700
04 Orbit-trap Julia set (PNG) 11.950 1.081 0.380 0.358 0.416 0.473 0.504 0.466 0.471 0.482 0.469 28.702 4.237 7.592 3.129
05 Mandelbrot zoom (GIF) 14.538 1.262 0.555 0.569 1.710 0.703 0.680 0.691 0.689 0.695 0.687 14.892 17.852 8.871 5.551
06 Julia parameter sweep (GIF) 9.627 0.507 0.546 0.407 0.329 0.626 0.619 0.622 0.621 0.624 0.629 10.704 11.122 11.067 3.694
07 Game of Life (GIF) 5.134 0.685 0.363 0.369 1.530 1.364 1.311 1.191 1.248 1.290 1.267 11.205 8.036 5.225 0.857
08 Langton's Ant (GIF) 5.220 0.767 0.452 0.483 2.213 2.031 1.997 1.912 2.011 1.886 2.019 18.824 10.367 6.446 2.218
09 Flame simulation (GIF) 10.895 1.167 0.611 0.661 6.566 2.374 2.290 2.368 2.265 2.306 2.358 32.077 18.097 18.956 2.356
10 Plasma effect (GIF) 6.194 0.876 0.684 0.554 2.646 1.444 1.886 1.397 1.414 1.444 1.319 11.745 7.806 4.525 1.994
11 Lissajous particles (GIF) 3.582 0.532 0.356 0.359 0.714 1.425 1.406 1.389 1.365 1.371 1.413 7.950 7.809 3.406 0.131
12 Sorting visualization (GIF) 3.864 0.552 0.344 0.362 0.680 1.341 1.343 1.309 1.348 1.328 1.306 8.087 7.078 4.057 0.233
13 Maze generation steps (GIF) 3.402 0.533 0.287 0.298 1.037 1.038 1.035 0.985 1.025 0.997 0.987 6.825 6.288 3.735 0.006
14 Simple ray marching (GIF) 2.670 0.300 0.160 0.159 0.606 0.489 0.573 0.490 0.513 0.503 0.492 3.800 3.370 2.138 0.864
15 Wave interference loop (GIF) 2.631 0.402 0.299 0.252 1.196 0.616 0.794 0.609 0.614 0.629 0.612 5.142 3.316 2.496 0.900
16 Chaos rotation of glass sculpture (GIF) 6.847 0.606 0.277 0.246 1.220 0.650 0.822 0.638 0.643 0.667 0.643 8.743 8.059 15.675 -
17 Monte Carlo Pi approximation 2.981 0.105 0.019 0.018 0.098 0.431 0.433 0.432 0.433 0.436 0.436 1.988 0.534 0.279 0.638
18 Mini-language interpreter 2.037 0.601 0.610 0.427 0.735 0.446 0.446 0.405 0.417 0.423 0.417 7.854 2.403 0.885 -

06_julia_parameter_sweep

Sample code: 06_julia_parameter_sweep.py
Transpiled code (C++ | Rust | C# | JavaScript | TypeScript | Go | Java | Swift | Kotlin | Ruby | Scala3 | PHP)

16_glass_sculpture_chaos

Sample code: 16_glass_sculpture_chaos.py
Transpiled code (C++ | Rust | C# | JavaScript | TypeScript | Go | Java | Swift | Kotlin | Ruby | Scala3 | PHP)

License

Apache License 2.0

About

Ultimate transpiler: converts Python to C++, Rust, C#, JavaScript, TypeScript, Go, Java, Swift, Kotlin, Ruby, Lua, Scala3, PHP, and Nim.

Topics

Resources

License

Stars

Watchers

Forks

Contributors