pyj — Python with braces
Python that survives copy-paste. Write blocks in { } instead of indentation, and your code keeps working after a chat app, a web form, a template or a shell one-liner has eaten the whitespace. .pyj files run directly with python, import like normal modules, and tracebacks point back to your original lines and columns.
pip install pybrace # Python 3.8+; on PyPI it is "pybrace", the module and the command are "pyj"
pyj -c 'for i in range(3) { if i % 2 { print(i, "odd") } else { print(i, "even") } }'
# fib.pyj — no significant whitespace, so reformatting can't break it
def fib(n) { a, b = 0, 1; for _ in range(n) { a, b = b, a + b }; return a }
if __name__ == "__main__" { print([fib(i) for i in range(10)]) }
$ python fib.pyj
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
Who is it for?
- Code that travels: snippets pasted into chats, issue comments, spreadsheets, database fields, templates or
python -c, where indentation gets lost or mangled. - Programmers coming from C, Java or JavaScript who like to see where a block ends.
- Teaching, generated code, and one-liners: anything that is easier to write without counting spaces.
Python's own answer to braces is from __future__ import braces → SyntaxError: not a chance. pyj doesn't change Python itself: it is a single-file, zero-dependency preprocessor, and you can leave it any time — pyj build fib.pyj writes a plain, indented fib.py:
# fib.pyj — no significant whitespace, so reformatting can't break it
def fib(n):
a, b = 0, 1
for _ in range(n):
a, b = b, a + b
return a
if __name__ == "__main__":
print([fib(i) for i in range(10)])
Features
- Single file, zero dependencies: the whole tool is one
pyj.pythat uses only the standard library, and it installs itself without pip or root. - Transparent execution: once installed,
python app.pyjjust works, any program canimporta.pyjmodule, and.pyand.pyjfiles can be mixed freely. - Shell one-liners too:
pyj -c 'for i in range(3) { print(i) }', or pipe code intopyj. - Errors point to your source: tracebacks, syntax errors and
inspect.getsourceall show.pyjlines and columns. - Dicts and sets work as usual: pyj tells a block
{apart from a literal{. - Cross-platform: Python 3.8+, tested in CI on Linux, macOS and Windows.
Installation
Debian, Ubuntu and other systems where pip is restricted
No pip, no sudo, no special flags. Three commands:
curl -O https://raw.githubusercontent.com/yyszh01/pyj/main/pyj.py
python3 pyj.py install
rm pyj.py
install copies pyj into your user site-packages, enables .pyj support for every python3 you run, and adds the pyj command to ~/.local/bin. The downloaded file is no longer needed. If your shell cannot find pyj, add ~/.local/bin to PATH (e.g. export PATH="$HOME/.local/bin:$PATH" in ~/.bashrc); python3 app.pyj works without it.
To upgrade, repeat the three commands. To remove: pyj uninstall. Run inside an activated virtual environment, install puts pyj into that environment instead.
With pip
pip install pybrace
After installing, every Python process in that environment understands .pyj files, and pip uninstall pybrace removes it completely. The package is named pybrace on PyPI, but the module and the command are both pyj. It is not affiliated with mayank-verma048/PyBrace, an unrelated project with a similar name.
On systems that mark the system Python as externally managed (PEP 668), pip install fails with error: externally-managed-environment. Use the installer above, or one of these:
# Into your user directory; with --user the flag still only writes to ~/.local,
# and pybrace has no dependencies that could conflict with apt
pip install --user --break-system-packages pybrace
# A virtual environment (recommended for projects): only that venv supports .pyj
python3 -m venv .venv && . .venv/bin/activate && pip install pybrace
pipx install pybrace also works but gives you only the pyj command: plain python3 app.pyj and imports do not support .pyj that way.
Usage
python app.pyj arg1 arg2 # run a file directly
python -c "import mymod" # import any .pyj module; packages can use __init__.pyj
pyj app.pyj arg1 arg2 # same as python app.pyj
pyj -c 'for i in range(3) { print(i) }' # run code from the command line, like python -c
echo 'if 1 { print("hi") }' | pyj # run code from stdin (or: pyj - args...)
pyj build app.pyj # write app.py
pyj build -c 'def f(x) { return x * 2 }' # print the Python for some code (pyj build - reads stdin)
python -m pyj ... is the same as pyj .... Without installing, run the downloaded file the same way: python pyj.py -c '...', python pyj.py build app.pyj.
.pyjand.pymodules can import each other. If bothfoo.pyandfoo.pyjexist,foo.pyjwins.- Compiled code is cached in
__pycache__/<module>.pyj.cpython-XY.pyc. The cache is invalidated when the source file or pyj itself changes. - Code run with
-cor from stdin gets the same error locations as files: the traceback shows the offending line of your code. - How
python app.pyjworks: at startup Python runspyj_autoload.pthfrom site-packages. When it sees that the script is a.pyjfile, it replaces the process withpython -m pyj app.pyj(on Windows it starts a child process instead). Interpreter flags are preserved on Python 3.10+; on 3.8 and 3.9 they are not passed on.
From Python code:
import pyj
pyj.install_import_hook() # .pyj modules become importable
print(pyj.transpile("if x { y() }"))
code = pyj.compile_pyj(src, "file.pyj") # code object with positions mapped to the .pyj source
Error locations
Runtime exceptions, syntax errors, inspect.getsource and linecache all point to the exact line and column in the .pyj source. This holds even when several statements share a line or one expression spans several lines (Python shows columns in tracebacks from 3.11; on 3.8–3.10 tracebacks point to the right line):
File "util.pyj", line 3, in divide
return a /
~~^
b }
~
ZeroDivisionError: division by zero
How it works: while converting, pyj records where each token came from in the source. It parses the generated code with ast.parse, rewrites every AST node's position back to the source position, and then compiles.
Syntax
| Rule | Example |
|---|---|
Blocks use { }; indentation is free-form |
while x { x -= 1 } |
| The colon is optional | def f(): { ... } is the same as def f() { ... } |
Statements are separated by ; |
a = 1; b = 2 |
| A newline ends a statement when the statement is clearly complete | One statement per line needs no ; |
| Newlines inside brackets, or after a trailing operator or comma, are ignored | total = 1 +⏎2 |
A line starting with . , and or etc. continues the previous line |
s = text⏎.strip() |
else if is shorthand for elif |
} else if x { |
Empty blocks get pass automatically |
class E {} |
| Dicts and sets are written as usual | if k in {1, 2} { d = {} } |
How does pyj tell blocks from dicts? A { opens a block only when it ends the header of an if/for/while/def/class/try/with/match/case… statement, that is, when it follows a name, number, string, closing bracket, :, or else/try/finally/except. In Python an expression followed by { is never valid, so this is unambiguous.
Caveats
- A line starting with
(,[,-or*does not continue the previous line. This avoids the JavaScript pitfall wherea⏎(b)becomes a function call. To continue a line, put the operator at the end of the line or wrap the expression in parentheses. - In a compound statement header written as
if x: {...}, the{always opens a block. To put a dict expression after a one-lineif, wrap it in a normal{ }block. - Comments are preserved. A comment in the middle of an expression is moved to the end of that statement's line.
Comparison with similar projects
Other projects share the idea of Python with braces. pyj is not affiliated with any of them. Each project below was tested with its own conversion function on the inputs shown, and the result was run; every row can be reproduced.
python-with-braces
Tested version: python-with-braces 0.1.2, the latest release on PyPI as of October 2026, via PythonWithBraces().process_code().
| Input | python-with-braces 0.1.2 | pyj |
|---|---|---|
d = {"a": 1} |
Converted to d = :"a": 1, a SyntaxError |
✅ |
| A nested dict inside a block | SyntaxError | ✅ |
def f(x) { if x { return 1 } else { return 2 } } |
SyntaxError | ✅ |
class Myself {⏎x = 1⏎} |
Class renamed to My (every self on a class line is removed) |
✅ |
@staticmethod inside a class |
A self parameter is added and the indentation breaks |
✅ |
print("a => b") |
Runs, but prints a >= b (=> and =< are rewritten everywhere, including inside strings) |
✅ |
| Uncaught exception at run time | Traceback shows <string>; exit status 0 |
Traceback shows the .pyj file, line and column; exit status 1 |
python app.pyj / import a module |
Not supported; run through its pwb command |
✅ |
pybraces
Tested version: pybraces 0.2.0, the latest release on PyPI as of October 2026, via braces2py().
pybraces is designed for shell one-liners and uses its own, deliberately stricter syntax: blocks are written : {, and newlines count as spaces, so statements must be separated by ;. Within that syntax it worked correctly on dicts, nested dicts, classes, decorators and f-strings, and pyj runs the same code unchanged. The differences:
| pybraces 0.2.0 | pyj | |
|---|---|---|
if x { ... } without the colon |
Not supported (by design) | ✅ |
One statement per line without ; |
Not supported (by design: newlines are spaces) | ✅ |
f = lambda: {"a": 1}; print(f()) |
SyntaxError: the : { after lambda is taken as a block |
✅ |
| Code from the shell | pyb -c CODE, stdin, and -M to auto-import standard modules |
pyj -c CODE, stdin |
| Files and modules | Runs a file with pyb FILE; .pyj-style imports are not supported |
python app.pyj, import |
| Error locations | Runs the converted code with python -c, so tracebacks refer to the converted code |
Tracebacks point to the original code |
| Dependencies | regex==2024.7.24, which has no prebuilt wheel for Python 3.14, so installing there needs a C compiler |
None |
Others
mayank-verma048/PyBrace (2018) is a Python 2 line-based converter: { must end a line and } must stand on its own line, and files must be converted to .py before running. Bython is earlier prior art; it is not compared here.
Feedback
pyj is young, and feedback decides where it goes next.
- Found a bug? Open an issue. The form asks for your pyj and Python versions and a small
.pyjsnippet. - A question, an idea, or a place where pyj saved you? Post in Discussions. Hearing how you use it helps the most.
- English, 中文 and 日本語 are all welcome.
If pyj is useful to you, a ⭐ on GitHub helps others find it.
Development
python -m unittest discover -s tests -v
License
Metadata
Release files for pybrace 0.1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pybrace-0.1.5.tar.gz | 31.9 kB | With provenance | Details for pybrace-0.1.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pybrace-0.1.5-py3-none-any.whl | Python 3 | none | any | Details for pybrace-0.1.5-py3-none-any.whl |
Total release size: 49.9 kB
Release files / pybrace-0.1.5.tar.gz
| Download URL | pybrace-0.1.5.tar.gz |
|---|---|
| Size | 31.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a9596b83bbb9b747795fef204ac83f1f2254b4217a25eea1c33948822c2fd39a
|
|
BLAKE2b-256 checksum How to use checksums |
e345e1dad42fe8d2da63e6e2fcd851975f485f420e8ac5f5be9df36fca947615
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.
Transparency logRelease files / pybrace-0.1.5-py3-none-any.whl
| Download URL | pybrace-0.1.5-py3-none-any.whl |
|---|---|
| Size | 18.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bffd36f5ca1bde0fefb1caaec85950cf4b97ead6aca73a927707117065e3ca0c
|
|
BLAKE2b-256 checksum How to use checksums |
ffe341805901af7b1ee42316a0dd40458710171c688f72dd08c6610e6115be44
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.
Transparency logSecurity for pybrace 0.1.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for pybrace-0.1.5.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.