Skip to main content

PyLGEN

PyPI - 0.7.3 PyPI - 3.12 PyPI - LICENSE CI codecov Socket Badge 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.3] - 2026-10-20

Fixed

  • Breaking: Typo error on ParseTreeNode, property childrens was replaced by children.
  • Fixed edge case on hash computation of LR0Item, LR0State, LR1Item, LR1State, LALRItem and LALRState.

[0.7.2] - 2026-10-09

Added

  • Support for extended Latin characters (accented vowels, diaeresis, and eñe: á é í ó ú ü ñ and their uppercase forms) as literals in regular expressions.
  • Support for Spanish punctuation marks (¿ ¡ « ») as literals.

Changed

  • Breaking: the lexer and the constants (\D, \S, \W, ., and the default negated class) now operate over the extended alphabet instead of string.printable. Inputs containing non-ASCII characters that previously produced a tokenization error are now recognized as CHAR.
  • Breaking: the complement of a character class ([^...]) is computed against the extended alphabet, not string.printable.

Fixed

  • Regular expressions containing Spanish letters (niño, camión, pingüino, …) failed in the lexer because those characters were not in string.printable.
  • The ¡ and ¿ signs are no longer discarded as invalid characters.

[0.7.1] - 2026-09-28

Fixed

  • BaseLexer wrong behavior with idented languages.

[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.3

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.3
File Size Uploaded Provenance Actions
pylgen_core-0.7.3.tar.gz 2.2 MB Without provenance Details for pylgen_core-0.7.3.tar.gz

Built distributions (wheels)

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

Total release size: 90.6 MB

Release files / pylgen_core-0.7.3.tar.gz

Download URL pylgen_core-0.7.3.tar.gz
Size 2.2 MB
Tags Source
SHA-256 checksum
How to use checksums
b52adaa7a5e0bfddc91d68ee05ec023716efaa5e12a876f6890523474eaca6c6
BLAKE2b-256 checksum
How to use checksums
dc7579014b81d5a932067e43048058098e74cf1434cfaf18e21c1f59860226bb
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.3-cp314-cp314-win_amd64.whl

Download URL pylgen_core-0.7.3-cp314-cp314-win_amd64.whl
Size 3.2 MB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
b147bce2c8343b1ba36384be92c591a4365d0d6a0c991da3e83cb5dac2b4633d
BLAKE2b-256 checksum
How to use checksums
f3b2219b0975a06612b236cf1549c75512e1a1a138410fea87c0c1179f723a0d
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.3-cp314-cp314-musllinux_1_2_x86_64.whl

Download URL pylgen_core-0.7.3-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
1bcec180ce24b08feece9cd176699abe5c33b633038055a28e6fa5d1b4352742
BLAKE2b-256 checksum
How to use checksums
0e7c34496de83634ff59713489fcc04f98045d3816b0f5339cfcecc4bf8d3569
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.3-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL pylgen_core-0.7.3-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 9.7 MB
Tags CPython 3.14 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
2fc98a00199efb8112ef99e2f1243601f4db18461e058d6e98aeb644f4c1ee2b
BLAKE2b-256 checksum
How to use checksums
ab676089ddd2f841fc3eb50a9cf843a616a82a0c187d8fe1b95f23cfd67c88bc
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.3-cp314-cp314-macosx_11_0_arm64.whl

Download URL pylgen_core-0.7.3-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
0442cc7eae6db41717abce969363cdb34bae99bf9248e93a0d04ad8990111733
BLAKE2b-256 checksum
How to use checksums
80790da36667e977623f6e85d0785d0070b48748da5f92c8dd1d72758347c054
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.3-cp314-cp314-macosx_10_15_x86_64.whl

Download URL pylgen_core-0.7.3-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
4f29c3ae60476a82325e1044faab7bed7f8c66601e11baf2b8f1109751969139
BLAKE2b-256 checksum
How to use checksums
336c79f87c867d16590a54ad4f1d8a3b3ddf616ff388586ea1fae7d2c5b388fe
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.3-cp313-cp313-win_amd64.whl

Download URL pylgen_core-0.7.3-cp313-cp313-win_amd64.whl
Size 3.1 MB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
1df7b71d9718e6bfd34bea740f079f97b982b8eeb803ac5d9176dead8cef551c
BLAKE2b-256 checksum
How to use checksums
bd519953c3a0a7bbe3e664f768e6d6b3cadabe89dc8fb250c6b14ac6db30a83c
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.3-cp313-cp313-musllinux_1_2_x86_64.whl

Download URL pylgen_core-0.7.3-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
259e8732beaf3f5fcaed524d96bb93ed6e7827bb399ed906d42494af31d4dc4f
BLAKE2b-256 checksum
How to use checksums
f8c34ee94b770c5553ae0f4846d39cfadba4f9b97f5399329e29414fb5d6bdd6
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.3-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL pylgen_core-0.7.3-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
0e7d3010f2f5d5e2f796743b685bd5827a23e5c6354b4051e347d93cedada349
BLAKE2b-256 checksum
How to use checksums
bb171583bbdbb9d1190ad926a30c5c34ffc2207c7725cb70ba5ce522e76be218
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.3-cp313-cp313-macosx_11_0_arm64.whl

Download URL pylgen_core-0.7.3-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
8774c6d571e0cadfd5a17a28efd74e5d2bad8fe1cb7d8a132ab411b2cdd3538a
BLAKE2b-256 checksum
How to use checksums
664cca050da09811cca6c78d53c49ccb48860f82568bc3dede31bebccfab783f
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.3-cp313-cp313-macosx_10_13_x86_64.whl

Download URL pylgen_core-0.7.3-cp313-cp313-macosx_10_13_x86_64.whl
Size 3.4 MB
Tags CPython 3.13 macOS 10.13+ x86-64
SHA-256 checksum
How to use checksums
17b90c45ee3fa80062afc8ad095d667c3edb66dacf8a7652da93d486fb3b8484
BLAKE2b-256 checksum
How to use checksums
93fa9e2b9924b79127d6419c26f405ca104b6fad5d226114b995ac5f44e0b010
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.3-cp312-cp312-win_amd64.whl

Download URL pylgen_core-0.7.3-cp312-cp312-win_amd64.whl
Size 3.1 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
3c55fc1a8a4215e574be92d9a24153bff7ec25a9f349e6d635dfc11d5acaf941
BLAKE2b-256 checksum
How to use checksums
9ec49ff64e0110c4a6c73b4fc3699481c887ada0ce4594194378da91cc5140a5
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.3-cp312-cp312-musllinux_1_2_x86_64.whl

Download URL pylgen_core-0.7.3-cp312-cp312-musllinux_1_2_x86_64.whl
Size 9.9 MB
Tags CPython 3.12 Linux musl 1.2+ x86-64
SHA-256 checksum
How to use checksums
b83b4140556702a36a523080d8386cfb50238c4aacc1adfb25504f6bea4eb92f
BLAKE2b-256 checksum
How to use checksums
7c1bb5d831d3d053c927f577af252b88e0a7ece1c8603d9cd65aad7509a51d2a
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.3-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL pylgen_core-0.7.3-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 9.9 MB
Tags CPython 3.12 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
bcdac506a50c9190258886d56ed6797c0ca0be4cf2b47f58726cc9e2a3b3a18a
BLAKE2b-256 checksum
How to use checksums
a6ef269710c89ba65916695875eb0ab423046a3b3d13d1fc8d7359cb3f20b192
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.3-cp312-cp312-macosx_11_0_arm64.whl

Download URL pylgen_core-0.7.3-cp312-cp312-macosx_11_0_arm64.whl
Size 3.4 MB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
741da1cd9364a8b7819e628ca48e020f7f097392e872b0ca1768ab19811a4c6a
BLAKE2b-256 checksum
How to use checksums
3e9c9586fdf11b5face0f2556a9c8858b760cedf92999f6b6e8523b3751e87a6
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.3-cp312-cp312-macosx_10_13_x86_64.whl

Download URL pylgen_core-0.7.3-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
99a3ba2bc9072ba0d03bbab592bb86ceabfc6c7645eaca53b49d7524b256c030
BLAKE2b-256 checksum
How to use checksums
e1d0ff8cfb1940f6185990cbe5ab351ae8ccd9922f00fcde0855e37e7c6fffe7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.7

Security for pylgen-core 0.7.3

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A 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.

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