r/Python • u/AutoModerator • Oct 04 '26
Showcase Showcase Thread
Post all of your code/projects/showcases/AI slop here.
Recycles once a month.
23
Upvotes
r/Python • u/AutoModerator • Oct 04 '26
Post all of your code/projects/showcases/AI slop here.
Recycles once a month.
1
u/Unique-Side-4443 Oct 08 '26
zsuite: build your own programming language or DSL in Python, compiled to native code, with an editor server included
What My Project Does
zsuite is a toolkit for building languages, from full programming languages to small DSLs and data formats. You describe each stage in Python and get a fast implementation:
Syntax (zgram): write a PEG grammar and get a native parser with ASTs, readable error messages and error recovery.
Checks (zrules): declare rules as selectors over node kinds ("
breakonly inside a loop", "each name defined once per scope", type rules with generics and unions) and get diagnostics with source positions.Execution (zrun): write what each construct does as an ordinary Python function taking the node and a runtime object. zrun partially evaluates those functions against the program's tree and compiles the result to native code. Your interpreter is plain Python you can debug, and it runs compiled.
Editors (zlsp): a Language Server built from the grammar and rules alone: diagnostics, go to definition, completion, hover.
You can also turn a program into a single-file executable that runs on machines without Python.
zsuite newgenerates a small working language with one file per stage plus tests, ready to change.Here's what semantics look like (from the tutorial's language): plain Python, one function per node kind:
How fast?
The main example is a subset of Lua 5.4. It covers the core language, metatables, closures, varargs, tail calls and most of the string/table/math libraries, but not coroutines,
goto,loadorutf8(full list). Its semantics are about 2,300 lines of Python. On four small benchmarks:fib(30)That's 17–400× faster than running the same semantics as Python, and 1.6–3.2× slower than the official C interpreter. In the typed-language example, typed code runs within about 2× of C.
Under the hood every package is a native extension written in Zig, using LLVM for code generation. Wheels use the stable ABI, so one wheel covers CPython 3.10 and later.
Target Audience
People building DSLs, config or rule languages, query languages, or teaching and hobby languages, who want a real parser, checker and editor support without writing each from scratch.
People who've written a tree-walking interpreter in Python and hit its speed limit.
It's alpha (all packages are 0.x), with CI on Linux and Windows x86_64. There's no macOS or ARM yet. I'd call it usable for tools and experiments, not yet something to bet a product on.
Comparison
Lark / parsimonious / pyparsing: parsing only, in Python. zgram compiles grammars to native code and is one stage of four; checks, execution and the LSP build on its trees.
ANTLR: generates parsers and leaves the rest to you. It needs a Java toolchain to generate, and you write the visitors and the language server yourself.
tree-sitter: great for editor parsing, but it stops at the tree, and grammars are written in JS and compiled with a C toolchain. zsuite also covers checks and execution, all from Python.
RPython (the PyPy toolchain): the closest idea, a fast interpreter from a Python description. RPython needs a restricted Python and a long translation step. zrun takes ordinary Python semantics and compiles per program at run time, with a cache. The trade-off is that RPython's JIT is far more mature.
Truffle/Graal: partial evaluation of interpreters too, but in Java on the JVM.
Writing it by hand in C or Rust: faster at the top end; Lua's own interpreter still beats the example by 1.6–3.2×. zsuite is much less work, and the semantics stay readable Python.
Links
Repo, tutorial, best practices and design: https://github.com/dzonerzy/zsuite
The packages: zgram, zrules, zrun, zlsp
Feedback welcome, especially from anyone who's built a DSL and can tell me what they'd have needed.