pyj
Write Python like JavaScript: blocks in { }, statements separated by ; or newlines, and no significant whitespace.
def fib(n) { a, b = 0, 1; for _ in range(n) { a, b = b, a + b }; return a }
if n < 0 { print("negative") } else if n == 0 { print("zero") }
else { print("positive") }
config = {"name": "pyj", "tags": {"a", "b"}} # dicts and sets work as usual
Features
- Transparent execution: once installed,
python app.pyjjust works, any program canimporta.pyjmodule, and.pyand.pyjfiles can be mixed freely. - Errors point to your source: tracebacks, syntax errors and
inspect.getsourceshow the exact.pyjline and column. - Dicts and sets work as usual: a
{opens a block only at the end of a statement header. - Shell one-liners:
pyj -c 'for i in range(3) { print(i) }', or pipe code intopyj. - Single file, zero dependencies: installs itself without pip or root.
- Cross-platform: Python 3.10+, tested on Linux, macOS and Windows.
Install
pip install pybrace
On Debian, Ubuntu and other systems where pip is restricted, no pip or sudo is needed:
curl -O https://raw.githubusercontent.com/yyszh01/pyj/main/pyj.py
python3 pyj.py install
rm pyj.py
Errors point back to the source
File "util.pyj", line 1, in divide
def divide(a, b) { return a /
~~^
b }
~
ZeroDivisionError: division by zero
While converting, pyj records where each token came from. It parses the generated code with ast.parse, rewrites every AST node's position back to the source position, and then compiles.
Full documentation, syntax rules and a comparison with similar projects are in the README.