Skip to content

About

A superset of Python with many new features, including multiline comments, header files, and optional curly brackets around control statements

Topics

Resources

Contributing

Security policy

Stars

3 stars

Watchers

2 watching

Forks

Repository files navigation

reStructuredPython

A lightweight Python source-to-source compiler with optional brace blocks, function pipelines, multiline comments, reusable headers, and a direct script launcher.

PyPI Python Tests License

Documentation · Website · VS Code extension

Get started

Requires Python 3.11 or newer. Prebuilt CPython wheels include the C compiler accelerator. No external runtime dependencies are required; source installs can fall back to Python if a C compiler is unavailable.

python -m pip install restructuredpython

greetings.cdata

def greet(name) {
    return f"Hello, {name}! 👋"
}

main.repy

include 'greetings.cdata'

/* Read a name and transform it through a pipeline. */
name = input("Your name 🌍: ")
message = name |> str.strip |> greet

if message {
    print(message)
}
repy main.repy           # Compile to main.py
repycl main.repy         # Transpile and run without writing a .py file
repy --check main.repy   # Validate without writing
repy main.repy -o app.py # Choose an output file
python -m restructuredpython --help

Brace blocks still use Python indentation. Existing valid Python is preserved, and REPY syntax is translated to ordinary Python. Source files and headers use UTF-8 (including emoji and non-Latin scripts); UTF-8 BOM and Windows line endings are accepted.

Python API

import restructuredpython as repy

code = repy.parse('result = "你好 👋" |> str.upper')
output = repy.compile_file("main.repy")
repy.run_file("main.repy", args=["example"])

parse() returns generated source. compile_file() validates before writing and returns the output path. Output must be a regular .py file, not a source file or symbolic link. Includes are confined to the source directory (or an explicitly selected include_root); project compilation uses the directory containing repyconfig.toml as the root. Project outputs are staged before replacement, with best-effort rollback if replacement fails. run_file() executes trusted scripts in the current interpreter with serialized, fresh main namespaces; it is not a sandbox.

Project configuration

Create a repyconfig.toml:

[config]
compile = "all"
exclude = ["./tests/*", "./docs/*"]

[modes.full]
exclude = []
repy repyconfig.toml
repy repyconfig.toml --mode full --check

Paths are relative to the directory containing repyconfig.toml. Individual files use their nearest ancestor config, if present. Explicit loop unrolling is bounded by max_unroll = 128 (config) or --max-unroll 512 (CLI override), with a hard factor ceiling of 4096 and a separate expansion budget.

Compiler performance

The C accelerator handles Unicode-aware lexical scanning, delimiter nesting and top-level pipeline detection. Python retains the reference implementation and high-level compiler orchestration. This speeds up transpilation, not the execution of generated Python programs.

To force the reference backend, set REPY_PURE_PYTHON=1 before importing the package. To measure both backends on identical generated source, install the native extension and run python benchmarks/compiler.py --blocks 5000. The benchmark reports both scanner-only and end-to-end transpilation throughput.

Development

python -m pip install -e .
python -m unittest discover -s tests -v
python -m compileall -q restructuredpython

See the contributing guide, syntax guide, and changelog.

Licensed under Apache-2.0.

About

A superset of Python with many new features, including multiline comments, header files, and optional curly brackets around control statements

Topics

Resources

Contributing

Security policy

Stars

3 stars

Watchers

2 watching

Forks

Releases

Used by

Contributors

Languages