Read in English

Pytra Code Alchemist

Pytra

Python は Pytra の入力言語で、Pytra はそのコードを複数のターゲット言語へトランスパイルします。

· Supported Backends ·

C++ Rust C# PowerShell JS TS Dart Go
Java Scala3 Kotlin Swift Ruby Lua PHP Nim Julia Zig
## Pytraの特徴 **🐍 Python → 各言語のネイティブコードへ** - 🌐 C++ / Rust / Go / Java / TS ほか多数へ変換 - 🧩 元コードの構造をほぼそのまま維持 - ⚡ Pythonで書いても高性能コードを生成 - ✨ Pythonサブセットでシンプル - 🛠 VS Codeなど既存ツールがそのまま使える - 🔧 本体もPython製で拡張しやすい - 🔁 自己変換できるセルフホスティング対応 ## 実行速度の比較 Pythonで書かれたサンプルコードの実行時間と、そのトランスパイルしたソースコードでの実行時間。(単位: 秒) 表中のPythonは元のコード、PyPyは参考用です。 |No.|内容|Python|PyPy|C++|Rust|C%23|JS| |-|-|-:|-:|-:|-:|-:|-:| |06 |ジュリア集合パラメータ掃引(GIF)|9.627|0.507|0.546|0.407|0.329|0.626| |16 |ガラス彫刻のカオス回転(GIF)|6.847|0.606|0.277|0.246|1.220|0.650| 全言語・全サンプルのデータ → [サンプルページ](../../sample/README-ja.md#実行速度の比較)
![06_julia_parameter_sweep](../../sample/images/06_julia_parameter_sweep.gif)
サンプルコード : 06_julia_parameter_sweep.py - ソース全体: [sample/py/06_julia_parameter_sweep.py](../../sample/py/06_julia_parameter_sweep.py)
変換後コード(各言語) [C++](../../sample/cpp/06_julia_parameter_sweep.cpp) | [Rust](../../sample/rs/06_julia_parameter_sweep.rs) | [C#](../../sample/cs/06_julia_parameter_sweep.cs) | [JS](../../sample/js/06_julia_parameter_sweep.js) | [TS](../../sample/ts/06_julia_parameter_sweep.ts) | [Dart](../../sample/dart/06_julia_parameter_sweep.dart) | [Go](../../sample/go/06_julia_parameter_sweep.go) | [Java](../../sample/java/06_julia_parameter_sweep.java) | [Swift](../../sample/swift/06_julia_parameter_sweep.swift) | [Kotlin](../../sample/kotlin/06_julia_parameter_sweep.kt) | [Ruby](../../sample/ruby/06_julia_parameter_sweep.rb) | [Lua](../../sample/lua/06_julia_parameter_sweep.lua) | [Scala3](../../sample/scala/06_julia_parameter_sweep.scala) | [PHP](../../sample/php/06_julia_parameter_sweep.php) | [Julia](../../sample/julia/06_julia_parameter_sweep.jl)
![16_glass_sculpture_chaos](../../sample/images/16_glass_sculpture_chaos.gif)
サンプルコード : 16_glass_sculpture_chaos.py - ソース全体: [sample/py/16_glass_sculpture_chaos.py](../../sample/py/16_glass_sculpture_chaos.py)
変換後コード(各言語) [C++](../../sample/cpp/16_glass_sculpture_chaos.cpp) | [Rust](../../sample/rs/16_glass_sculpture_chaos.rs) | [C#](../../sample/cs/16_glass_sculpture_chaos.cs) | [JS](../../sample/js/16_glass_sculpture_chaos.js) | [TS](../../sample/ts/16_glass_sculpture_chaos.ts) | [Dart](../../sample/dart/16_glass_sculpture_chaos.dart) | [Go](../../sample/go/16_glass_sculpture_chaos.go) | [Java](../../sample/java/16_glass_sculpture_chaos.java) | [Swift](../../sample/swift/16_glass_sculpture_chaos.swift) | [Kotlin](../../sample/kotlin/16_glass_sculpture_chaos.kt) | [Ruby](../../sample/ruby/16_glass_sculpture_chaos.rb) | [Lua](../../sample/lua/16_glass_sculpture_chaos.lua) | [Scala3](../../sample/scala/16_glass_sculpture_chaos.scala) | [PHP](../../sample/php/16_glass_sculpture_chaos.php) | [Julia](../../sample/julia/16_glass_sculpture_chaos.jl)
## Python vs C++ vs Rust vs Pytra 凡例: ✅ = 良い / 🔶 = 部分的・制限あり / ❌ = 非対応・困難 | 観点 | ![Python](https://img.shields.io/badge/-Python-3776AB?style=flat-square&logo=python&logoColor=white) | ![C++](https://img.shields.io/badge/-C%2B%2B-00599C?style=flat-square&logo=cplusplus&logoColor=white) | ![Rust](https://img.shields.io/badge/-Rust-F6B73C?style=flat-square&logo=rust&logoColor=black) | ![Pytra](https://img.shields.io/badge/-Pytra-875715?style=flat-square&labelColor=F4DB8E) | |-|-|-|-|-| | 構文 | ✅ シンプル | ❌ 複雑 | 🔶 所有権/
ライフタイム | ✅ Pythonと同じ | | 型安全性 | ❌ 動的 | ✅ 静的 | ✅ 静的 | ✅ 静的
(Python風注釈) | | 実行速度 | ❌ 遅い | ✅ 高速 | ✅ 高速 | ✅ 高速
(変換先に依存) | | メモリ管理 | ✅ GC
(楽だが重い) | ❌ 手動/
shared_ptr | 🔶 所有権
(安全だが難) | ✅ RCベース
で自動 | | 整数型 | 🔶 多倍長のみ | ✅ int8〜64 | ✅ i8〜i64 | ✅ int8〜64 | | float | 🔶 64-bitのみ | ✅ 32/64-bit | ✅ f32/f64 | ✅ 32/64-bit | | ビルド | ✅ 不要 | ❌ CMake等 | 🔶 cargo | ✅ `./pytra`
`--build --run` | | 多言語展開 | ❌ | ❌ | ❌ | ✅ 18言語 | | 最適化 | ❌ 限定的 | ✅ 豊富 | ✅ 豊富 | ✅ 変換先を活用 | | 配布 | 🔶 要runtime | ✅ バイナリ | ✅ バイナリ | ✅ 各言語固有 | | 単一継承 | ✅ | ✅ | ❌ traitのみ | ✅ | | 多重継承 | ✅ | 🔶 複雑 | ❌ | ❌ | | Mix-in | ✅ | 🔶 CRTP等 | ❌ | ✅ | | Trait/
Interface | 🔶 Protocol | 🔶 virtual base | ✅ ネイティブ | ✅ `@trait` | | 例外処理 | ✅ | ✅ | ❌ Result/panic | ✅ 全言語対応 | | テンプレート/
ジェネリクス | ❌ | 🔶 エラー難読 | ✅ | ✅ `@template` | | Selfhost | ❌ | ❌ | ❌ | ✅ | ## ドキュメントを読む | | ![English](https://img.shields.io/badge/English-2563EB?style=flat-square) | ![日本語](https://img.shields.io/badge/日本語-DC2626?style=flat-square) | |---|---|---| | Getting started | [Tutorial](../en/tutorial/README.md) | [チュートリアル](./tutorial/README.md) | | Guide | [Guides](../en/guide/README.md) | [ガイド](./guide/README.md) | | Specification | [Spec index](../en/spec/index.md) | [仕様書](./spec/index.md) | | Progress | [Project Progress](../en/progress/index.md) | [プロジェクト進捗](./progress/index.md) | ## 更新履歴 > **2026-04-10** — P0-ZIG-CREXC-S4 完了。Zig / Rust の exception / try / with 処理を CommonRenderer hook 経由で完全共有。Zig toolchain_ 依存解消(全言語 toolchain_ 依存 0)。Nim / Go / Lua 新規 fixture parity 完了。Lua copy elision 完成。 > **2026-04-09** — Zig / Rust の handler binding / panic / block expression helper を CommonRenderer に集約。 > **2026-04-08** — 全言語 lint 完全クリア達成(697→0)。18 言語全て 10/10 PASS。C# / Go / Nim parity 復旧。Nim emitter の文字列分割偽装撲滅。P0-ZIG-CREXC S1-S3 開始(Zig / Rust 例外処理の CommonRenderer 集約)。 > **2026-04-07** — lint 149 件 / 14 言語 10/10 PASS(697→149)。PyFile 廃止、IOBase 型階層を `built_in/io.py` に定義。emitter guide §12.7 追加。全言語横断で PyFile coupling 除去。 > **2026-04-06** — with 文を `__enter__`/`__exit__` プロトコルで実装(CommonRenderer try/finally + hoist)。with fixture 2 件追加。TS/JS shim cleanup 完了。Dart emitter guide 準拠。JVM backend 大幅進展。.east* 生成物を git 管理から除去。 > **2026-04-05** — containers.py `mut[T]` 注釈で `meta.mutates_receiver` 導入。C++ メソッド名ハードコード解消。mapping.json FQCN キー統一完了。toolchain リネーム完了。 [全履歴はこちら](./changelog.md) ## ライセンス Apache License 2.0