Skip to main content

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 / else
  • while
  • for over range(...)
  • 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.

Metadata

Release files for pycrusty 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pycrusty 0.2.0
File Size Uploaded
pycrusty-0.2.0.tar.gz 13.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pycrusty 0.2.0
File Interpreter ABI Platform
pycrusty-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 29.3 kB

Release files / pycrusty-0.2.0.tar.gz

Download URL pycrusty-0.2.0.tar.gz
Size 13.7 kB
Tags Source
SHA-256 checksum
How to use checksums
1fac686a8683165e606b0b5c28c9cca65162297ef0440aa88a97fa7b8d0e2957
BLAKE2b-256 checksum
How to use checksums
8f914a92b9734315758f9e9aae3b04d5f5225aa0e97c08c004fcbf651ba629dc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.11

Release files / pycrusty-0.2.0-py3-none-any.whl

Download URL pycrusty-0.2.0-py3-none-any.whl
Size 15.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
252b809cf1a72d221e7e8da1868cb1563aca050a947a544b9e35454ee29c4895
BLAKE2b-256 checksum
How to use checksums
0629221b5d28cfa70bc8c51345c18ef1ea621267ddfec0c051a1fcf1689f44ab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.11

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page