Skip to main content

PyLGEN

PyPI - 0.7.0 PyPI - 3.12 PyPI - LICENSE CI codecov Supported OS

From prototype to production: a Python-native compiler framework that brings the "Dragon Book" to life in Python, with clarity throughout.

PyLGEN gives you complete control over every stage of language processing. Build interpreters and compilers from scratch without leaving the Python ecosystem. Prototype rapidly in pure Python, then compile to native speed with Cython for production workloads.

Why PyLGEN?

  • Full pipeline control: You own every step: lexer, parser, AST, semantic analysis, and evaluation.

  • Dual‑nature design: Pure Python for development and debugging; Cython for near‑C performance.

  • Handles large inputs: 2‑million‑line files parsed in ~61.62 s, about 1.89x faster than Lark + lark_cython.

  • Python ecosystem integration: Leverage NumPy, SciPy, or any library from within your language.

📊 Benchmark at a Glance

Lark + lark_cython PyLGEN
Parsing (2M lines, 40 MB) 116.73 s 61.62 s
AST Construction Separate pass Integrated
Full Interpreter — ~67.52 s (incl. semantic checks + eval)
Peak Memory ~4 GB ~968 MB

more details in the benchmark section of documentation →

PyLGEN is a framework for building interpreters, covering the full compilation pipeline from lexical analysis to execution.

🚀 Minimal Example

from pylgen.lexer import Lexer
from pylgen.grammar import AttributedGrammar
from pylgen.parser import ParserBuilder, ParserType
from pylgen.common.enums import TokenType
from pylgen.common.types import Symbol

class TokenTypeEnum(TokenType):
    NUMBER = 'NUMBER'
    PLUS = 'PLUS'

    # ...

def mapping_function(t:TokenTypeEnum,tx:str) -> Symbol:
    # ....

# 1. Define tokens & lexer
lexer = Lexer(mapping_function, r'\s+')
lexer[0, TokenTypeEnum.NUMBER] = r'\d+'
lexer[1, TokenTypeEnum.PLUS]   = r'\+'

# 2. Define grammar with AST builders
# Assumes the following are already defined:
#   E, T, plus, binary_reductor, single_reductor
G = AttributedGrammar(Symbol('E'))
G[E] += (E, plus, T), binary_reductor
G[E] += (T,),        single_reductor

# 3. Build the parser
parser = ParserBuilder.build_parser_from_attributed(G, ParserType.LALR1)

# 4. Parse, analyse, execute
text = '1 + 2' # your text to parse
lexer.load_text(text)
ast = parser.parse(lexer.tokens)
# ... your semantic visitors & evaluator ...

🧩 Architecture

flowchart LR
    Source["Source Code"] --> Lexer["Lexer"]
    Lexer --> Parser["Parser LALR(1)"]
    Parser --> AST["AST"]
    AST --> Visitors["Visitors"]
    Visitors --> Result["Result / Errors"] 
Module Purpose
common Core types: Symbol, AST, Token, ASTListView, and error hierarchy
automaton Finite automata(DFA/NFA), determinization, Hopcroft minimization
regex Full regex engine -> automata conversion
lexer Regex‑based tokenization with priority and validation
grammar CFG and attributed grammar with reducers
parser LALR(1) parser generation and runtime
analysis Visitor pattern, traversal strategies, context management
visual Interactive HTML visualization of ASTs, parse trees, automata and parsing tables

All modules are fully usable from Python and Cython, prototype in Python, ship in C.

⚡ Quick Start

pip install pylgen-core

Then build your interpreter step by step, following the complete tutorial in the documentation.

📖 Learn More

  • Step‑by‑step tutorial: Build a full arithmetic REPL from scratch.

  • VecLang case study: Production‑grade language with vectors, functions, and slicing.

  • Deep‑dive API tour: Understand every module inside out.

  • Under the hood: Build a lexer and parser from scratch, using the same building blocks that the framework uses internally.

  • Examples: See practical examples of using PyLGEN to build interpreters and DSLs.

Read the full documentation →

PyLGEN: Where compiler theory meets Python pragmatism.

Contributing

Contributions are welcome. Please open an issue or submit a pull request. See Contributing.md for details.

License

This project is licensed under the BSD 3-Clause License. See LICENSE for details.

Changelog

All notable changes to this project are documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

[Unreleased]

[0.7.0] - 2026-09-27

Changed

  • AST now exposes start_position and end_position properties instead of separate line and column. The constructor now receives start_line, start_column, end_line, and end_column instead of just line and column. Breaking change for any subclass of AST or any reductor that instantiates AST nodes.

  • Moved ErrorType from pylgen.analysis.error_type to pylgen.common.enums. Update your imports accordingly. Breaking change.

  • Moved Error, LexicalError, SyntaxError, SemanticError and RuntimeError from pylgen.analysis.error to pylgen.common.types. Update your imports accordingly. Breaking change.

[0.6.2] - 2026-08-29

Fixed

  • Fixed type mismatches in BottomUpParser with the enum BottomUpParserAction.

Metadata

Release files for pylgen-core 0.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pylgen-core 0.7.0
File Size Uploaded
pylgen_core-0.7.0.tar.gz 2.2 MB Details

Built distributions (wheels)

Table of built distributions (wheels) for pylgen-core 0.7.0
File
pylgen_core-0.7.0-cp314-cp314-win_amd64.whl CPython 3.14 CPython 3.14 Windows x86-64 Details
pylgen_core-0.7.0-cp314-cp314-musllinux_1_2_x86_64.whl CPython 3.14 CPython 3.14 Linux musl 1.2+ x86-64 Details
pylgen_core-0.7.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.17+ x86-64 Details
pylgen_core-0.7.0-cp314-cp314-macosx_11_0_arm64.whl CPython 3.14 CPython 3.14 macOS 11.0+ ARM64 Details
pylgen_core-0.7.0-cp314-cp314-macosx_10_15_x86_64.whl CPython 3.14 CPython 3.14 macOS 10.15+ x86-64 Details
pylgen_core-0.7.0-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details
pylgen_core-0.7.0-cp313-cp313-musllinux_1_2_x86_64.whl CPython 3.13 CPython 3.13 Linux musl 1.2+ x86-64 Details
pylgen_core-0.7.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.17+ x86-64 Details
pylgen_core-0.7.0-cp313-cp313-macosx_11_0_arm64.whl CPython 3.13 CPython 3.13 macOS 11.0+ ARM64 Details
pylgen_core-0.7.0-cp313-cp313-macosx_10_13_x86_64.whl CPython 3.13 CPython 3.13 macOS 10.13+ x86-64 Details
pylgen_core-0.7.0-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details
pylgen_core-0.7.0-cp312-cp312-musllinux_1_2_x86_64.whl CPython 3.12 CPython 3.12 Linux musl 1.2+ x86-64 Details
pylgen_core-0.7.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ x86-64 Details
pylgen_core-0.7.0-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details
pylgen_core-0.7.0-cp312-cp312-macosx_10_13_x86_64.whl CPython 3.12 CPython 3.12 macOS 10.13+ x86-64 Details

Total release size: 89.9 MB

Release files / pylgen_core-0.7.0.tar.gz

Download URL pylgen_core-0.7.0.tar.gz
Size 2.2 MB
Tags Source
SHA-256 checksum
How to use checksums
dce84f7411ca2b1eb971045fd343b6a7ddcdc76a55c7b2db83178e093ef7e23b
BLAKE2b-256 checksum
How to use checksums
c2da9817376e1ea6d7a3289fb2d625eb7481a7e06574fe5bc32f601ea897a588
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.7

Release files / pylgen_core-0.7.0-cp314-cp314-win_amd64.whl

Download URL pylgen_core-0.7.0-cp314-cp314-win_amd64.whl
Size 3.2 MB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
849438bdafaa7dc4b12f48724071971ea0c6825e2cb49a7fb33967ff75bcb147
BLAKE2b-256 checksum
How to use checksums
36ca44edff5eeb85b2558309d797ba7a45c58b5275510eb86bfcaa46d9da8698
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.7

Release files / pylgen_core-0.7.0-cp314-cp314-musllinux_1_2_x86_64.whl

Download URL pylgen_core-0.7.0-cp314-cp314-musllinux_1_2_x86_64.whl
Size 9.7 MB
Tags CPython 3.14 Linux musl 1.2+ x86-64
SHA-256 checksum
How to use checksums
a8026e5f6101f2de3f5f6a3fb6f882733b5d136dcc9440a6456fb59890388479
BLAKE2b-256 checksum
How to use checksums
cdfb40ae5aca02b855ba3c7791d48e9b801f5909c86c808a4463cbecb8e3bbcd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.7

Release files / pylgen_core-0.7.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL pylgen_core-0.7.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 9.6 MB
Tags CPython 3.14 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
f9267699d0cff03b9421a01d1ae2e799190dea3c40c8d478818c2a62f336b790
BLAKE2b-256 checksum
How to use checksums
244b04368e4619a561dcee6933bfc3c9fceec66029a6c930599a623963f6752a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.7

Release files / pylgen_core-0.7.0-cp314-cp314-macosx_11_0_arm64.whl

Download URL pylgen_core-0.7.0-cp314-cp314-macosx_11_0_arm64.whl
Size 3.4 MB
Tags CPython 3.14 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
5bd8a33f085fa4123e1f2f7a817e5f9d84b1ff409e4149002c083517be1c6334
BLAKE2b-256 checksum
How to use checksums
e0c1c2ca68065f35602e4f6beeac5d9cc22f09ef5990b9a4718a8217382bd6fd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.7

Release files / pylgen_core-0.7.0-cp314-cp314-macosx_10_15_x86_64.whl

Download URL pylgen_core-0.7.0-cp314-cp314-macosx_10_15_x86_64.whl
Size 3.4 MB
Tags CPython 3.14 macOS 10.15+ x86-64
SHA-256 checksum
How to use checksums
68522b768e820c7f4ae78573e541756553e16284df9ce596710f880c3372f8f2
BLAKE2b-256 checksum
How to use checksums
ee89bf7db95edc688e5a9938898c96c195d685768deacc7ab7cf1e9a433d6ec0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.7

Release files / pylgen_core-0.7.0-cp313-cp313-win_amd64.whl

Download URL pylgen_core-0.7.0-cp313-cp313-win_amd64.whl
Size 3.1 MB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
81dbeab726dc2ded551b90ebd89477185a66546b1742b3275418eac4339e9512
BLAKE2b-256 checksum
How to use checksums
5811f4ad355215dc455066e6f561e5b2696682f91891b14c32e44925731faeac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.7

Release files / pylgen_core-0.7.0-cp313-cp313-musllinux_1_2_x86_64.whl

Download URL pylgen_core-0.7.0-cp313-cp313-musllinux_1_2_x86_64.whl
Size 9.7 MB
Tags CPython 3.13 Linux musl 1.2+ x86-64
SHA-256 checksum
How to use checksums
1d247b0d5f5dd8d72d151ec40053b718ebb8aec8fe43d7013e422bed6e3cbcee
BLAKE2b-256 checksum
How to use checksums
5fa39fb6fa8abeba9affe8e60e9d13aefd1590a2d67a138ee5cd6f672c4c314a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.7

Release files / pylgen_core-0.7.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL pylgen_core-0.7.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 9.7 MB
Tags CPython 3.13 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
5d1c80345b15e87a5b582571baac3a995783dfbdcdd0333f4bbc5fd96551d33e
BLAKE2b-256 checksum
How to use checksums
dae1c5e270ba8c43b8793130712dd6489e8ec00fec317ff8c92fe162bcb1183b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.7

Release files / pylgen_core-0.7.0-cp313-cp313-macosx_11_0_arm64.whl

Download URL pylgen_core-0.7.0-cp313-cp313-macosx_11_0_arm64.whl
Size 3.3 MB
Tags CPython 3.13 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
ff2741b727d130a2e54c0ee4ab2cd9169cad436b8ee8cc9fe2b631e1f25ab553
BLAKE2b-256 checksum
How to use checksums
cce9743dfa90f9829e5844c2f784fb023643b4f4a3fe954b41c45df8207b58f9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.7

Release files / pylgen_core-0.7.0-cp313-cp313-macosx_10_13_x86_64.whl

Download URL pylgen_core-0.7.0-cp313-cp313-macosx_10_13_x86_64.whl
Size 3.3 MB
Tags CPython 3.13 macOS 10.13+ x86-64
SHA-256 checksum
How to use checksums
aafc2cb2914e2692e3ae1c4068764a816abc817581f8c1dd307e490017fa5d8f
BLAKE2b-256 checksum
How to use checksums
2985de64e0ee61f1d5824379e25e774deb2740a9d83e863fef15df642ba2df6d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.7

Release files / pylgen_core-0.7.0-cp312-cp312-win_amd64.whl

Download URL pylgen_core-0.7.0-cp312-cp312-win_amd64.whl
Size 3.1 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
8cd21623b28b57a70dbaebd79f64fdf4de003ec22f1b0c1f557e326e1e6dc15e
BLAKE2b-256 checksum
How to use checksums
e0176ee2f7029064e851d052a60e84dd5747371b8843f084df06b80716e33522
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.7

Release files / pylgen_core-0.7.0-cp312-cp312-musllinux_1_2_x86_64.whl

Download URL pylgen_core-0.7.0-cp312-cp312-musllinux_1_2_x86_64.whl
Size 9.8 MB
Tags CPython 3.12 Linux musl 1.2+ x86-64
SHA-256 checksum
How to use checksums
45ec5de7097192c8153efc64bf65e6f025daae0dc9fb6ff34f0222c3636575c8
BLAKE2b-256 checksum
How to use checksums
1ab82bd8eed52057e149b42cd3b285d0d69cb9006dc3368ce966b86f81081cf1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.7

Release files / pylgen_core-0.7.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL pylgen_core-0.7.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 9.8 MB
Tags CPython 3.12 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
3be07d60d6208cbeab498b2404c3053f54169e00da92a37e3093f9a5724916e9
BLAKE2b-256 checksum
How to use checksums
2df6e7703cb99e8adcec399fd45959fa45793560c4d6e1c2822309bb8ef31631
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.7

Release files / pylgen_core-0.7.0-cp312-cp312-macosx_11_0_arm64.whl

Download URL pylgen_core-0.7.0-cp312-cp312-macosx_11_0_arm64.whl
Size 3.3 MB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
535d057fbf5902da4f4b70648bbbf77e48825bfb6142900c867d125ed369a745
BLAKE2b-256 checksum
How to use checksums
3dc0ccfa829450417eb256a1a134c7d34d0f26a9648cbad5767a2491288e99eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.7

Release files / pylgen_core-0.7.0-cp312-cp312-macosx_10_13_x86_64.whl

Download URL pylgen_core-0.7.0-cp312-cp312-macosx_10_13_x86_64.whl
Size 3.4 MB
Tags CPython 3.12 macOS 10.13+ x86-64
SHA-256 checksum
How to use checksums
9d9d81f1a5b98407a48f0721836d16238dd1d1cbbe2d643e8b6863781a6d3caf
BLAKE2b-256 checksum
How to use checksums
3af5a3732c889f6f264542b76b05245a6ce9a4958809b8e5a8397c89112d1702
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.7

Release history Release notifications | RSS feed

0.7.2

16 release files

0.7.1

16 release files

This release

0.7.0 This release

16 release files

0.6.3

16 release files

0.6.1

16 release files

0.6.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page