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

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.