A practical Python-to-Rust transpiler for a supported subset of Python
Project description
pythrust
pythrust transpiles a supported subset of Python into Rust and ships with a tiny runtime so the generated code is easy to inspect and extend.
Install
pip install .
Run from the command line
pythrust examples/example.py -o generated.rs
Read from standard input:
python -m pythrust - < examples/example.py
Use as a library
from pythrust import Transpiler, TranspilerConfig
source = """
def add(a, b):
return a + b
"""
transpiler = Transpiler(TranspilerConfig(optimize=True))
rust_code = transpiler.transpile(source)
print(rust_code)
Supported subset
- imports
- functions
- assignments and augmented assignments
if/elif/elsewhileforoverrange(...)break,continue,return,pass- expressions, calls, attributes, subscripts, lists, tuples, dicts
- constant folding and a few small algebraic simplifications
This project is intentionally small and practical: it aims to make transpiled output easy to read first, then optimize it incrementally.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pycrusty-0.2.0.tar.gz.
File metadata
- Download URL: pycrusty-0.2.0.tar.gz
- Upload date:
- Size: 13.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1fac686a8683165e606b0b5c28c9cca65162297ef0440aa88a97fa7b8d0e2957
|
|
| MD5 |
3280c0faf9215e982854d1afc0fb1d8b
|
|
| BLAKE2b-256 |
8f914a92b9734315758f9e9aae3b04d5f5225aa0e97c08c004fcbf651ba629dc
|
File details
Details for the file pycrusty-0.2.0-py3-none-any.whl.
File metadata
- Download URL: pycrusty-0.2.0-py3-none-any.whl
- Upload date:
- Size: 15.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
252b809cf1a72d221e7e8da1868cb1563aca050a947a544b9e35454ee29c4895
|
|
| MD5 |
8753a2263a0d42be85df35035d2a1e81
|
|
| BLAKE2b-256 |
0629221b5d28cfa70bc8c51345c18ef1ea621267ddfec0c051a1fcf1689f44ab
|