Skip to content

yaneurao/Pytra

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7,215 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

ζ—₯本θͺžγ§θͺ­γ‚€

Pytra Code Alchemist

Pytra

Python is Pytra's input language β€” Pytra transpiles that code into multiple target languages.

Β· Supported Backends Β·

C++ Rust C# PowerShell JS TS Dart Go
Java Scala3 Kotlin Swift Ruby Lua PHP Nim Julia Zig

Features

🐍 Python β†’ native code in each target language

  • 🌐 Transpiles to C++ / Rust / Go / Java / TS and many more
  • 🧩 Preserves the original code structure almost entirely
  • ⚑ Write in Python, generate high-performance code
  • ✨ Simple Python subset input
  • πŸ›  Works with existing tools like VS Code out of the box
  • πŸ”§ The transpiler itself is written in Python β€” easy to extend
  • πŸ” Self-hosting capable β€” can transpile itself

Performance Comparison

Execution time of sample code written in Python versus execution time of the same code after transpilation. (Unit: seconds.) The Python column is the original code; PyPy is included for reference.

No. Description Python PyPy C++ Rust C%23 JS
06 Julia set parameter sweep (GIF) 9.627 0.507 0.546 0.407 0.329 0.626
16 Glass sculpture chaos rotation (GIF) 6.847 0.606 0.277 0.246 1.220 0.650

Full data for all languages and all samples β†’ Sample page

06_julia_parameter_sweep

Sample code : 06_julia_parameter_sweep.py
Transpiled code (per language)

C++ | Rust | C# | JS | TS | Dart | Go | Java | Swift | Kotlin | Ruby | Lua | Scala3 | PHP | Julia

16_glass_sculpture_chaos

Sample code : 16_glass_sculpture_chaos.py
Transpiled code (per language)

C++ | Rust | C# | JS | TS | Dart | Go | Java | Swift | Kotlin | Ruby | Lua | Scala3 | PHP | Julia

Python vs C++ vs Rust vs Pytra

Legend: βœ… = Good / πŸ”Ά = Partial / limited / ❌ = Not supported / difficult

Aspect Python C++ Rust Pytra
Syntax βœ… Simple ❌ Complex πŸ”Ά Ownership/
lifetimes
βœ… Same as Python
Type safety ❌ Dynamic βœ… Static βœ… Static βœ… Static
(Python-style annotations)
Execution speed ❌ Slow βœ… Fast βœ… Fast βœ… Fast
(depends on target)
Memory management βœ… GC
(easy but heavy)
❌ Manual/
shared_ptr
πŸ”Ά Ownership
(safe but hard)
βœ… RC-based
automatic
Integer types πŸ”Ά Arbitrary precision only βœ… int8–64 βœ… i8–i64 βœ… int8–64
float πŸ”Ά 64-bit only βœ… 32/64-bit βœ… f32/f64 βœ… 32/64-bit
Build βœ… Not needed ❌ CMake etc. πŸ”Ά cargo βœ… ./pytra
--build --run
Multi-language output ❌ ❌ ❌ βœ… 18 languages
Optimization ❌ Limited βœ… Rich βœ… Rich βœ… Leverages target
Distribution πŸ”Ά Requires runtime βœ… Binary βœ… Binary βœ… Language-native
Single inheritance βœ… βœ… ❌ traits only βœ…
Multiple inheritance βœ… πŸ”Ά Complex ❌ ❌
Mix-in βœ… πŸ”Ά CRTP etc. ❌ βœ…
Trait/
Interface
πŸ”Ά Protocol πŸ”Ά virtual base βœ… Native βœ… @trait
Exception handling βœ… βœ… ❌ Result/panic βœ… All languages
Templates/
Generics
❌ πŸ”Ά Cryptic errors βœ… βœ… @template
Selfhost ❌ ❌ ❌ βœ…

Read the Docs

English ζ—₯本θͺž
Getting started Tutorial チγƒ₯γƒΌγƒˆγƒͺをル
Guide Guides ガむド
Specification Spec index δ»•ζ§˜ζ›Έ
Progress Project Progress γƒ—γƒ­γ‚Έγ‚§γ‚―γƒˆι€²ζ—

Changelog

2026-04-10 β€” P0-ZIG-CREXC-S4 complete. Zig / Rust exception / try / with handling fully shared via CommonRenderer hooks. Zig toolchain_ dependency eliminated (all languages now at 0). Nim / Go / Lua new fixture parity complete. Lua copy elision done.

2026-04-09 β€” Zig / Rust handler binding / panic / block expression helpers consolidated in CommonRenderer.

2026-04-08 β€” All languages lint clear (697β†’0). 18 languages at 10/10 PASS. C# / Go / Nim parity restored. Nim emitter string-split workaround eliminated. P0-ZIG-CREXC S1-S3 started.

2026-04-07 β€” Lint down to 149 / 14 languages at 10/10 PASS (697β†’149). PyFile abolished, IOBase hierarchy in built_in/io.py. Emitter guide Β§12.7. Cross-language PyFile coupling removal.

2026-04-06 β€” With statement via __enter__/__exit__ protocol (CommonRenderer try/finally + hoist). 2 with fixtures added. TS/JS shim cleanup complete. Dart emitter guide compliance. JVM major progress. .east* removed from git.

2026-04-05 β€” containers.py mut[T] annotations for meta.mutates_receiver. C++ method name hardcode removed. mapping.json FQCN key unification. Toolchain rename complete.

Full changelog

License

Apache License 2.0

About

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

Topics

Resources

License

Stars

Watchers

Forks

Contributors