pyparsing
Build recursive-descent parsers in Python without a separate grammar file
Repository Health
Technical Analysis
pyparsing lets you build parsers for structured or semi-structured text entirely in Python, by combining small parser-element objects (literals, words, numbers, quoted strings) with operators like + (sequence), | (first match), and ^ (longest match) into a grammar object that parses directly. There’s no separate grammar DSL, code-generation step, or external parser-generator tool to run — the grammar is ordinary Python code, which makes it easy to debug, extend, and combine with the rest of an application.
It predates most modern PEG-parser libraries in the Python ecosystem and remains widely used for config-file formats, small DSLs, log-line extraction, and search-query grammars where a full parser-generator toolchain would be overkill.
What You Get
- A library of composable parser-element primitives (
Word,Literal,Regex,QuotedString,Combine, and more) usable directly as Python objects - Operator-based grammar composition (
+for sequence,|for first-match-wins,^for longest-match,~for negation) - Parse actions - attach Python callables to grammar elements to transform or validate matched tokens during parsing
ParseResultsobjects supporting both positional and named-field access to parsed tokens, plus nested/grouped results- A
pyparsing.diagrammodule for generating railroad-diagram visualizations of a grammar, plus acommonmodule of ready-made tokens (numbers, identifiers, comments)
Common Use Cases
- Parsing small domain-specific languages or config-file formats without introducing a separate grammar-generator build step
- Extracting structured fields from semi-structured log lines or command output
- Building custom search-query or filter-expression grammars for an application’s search bar
- Validating and transforming input during parsing itself via attached parse actions, rather than in a separate post-processing pass
Under The Hood
Architecture - core.py implements the parser-combinator engine: every grammar element is a ParserElement subclass with a parseImpl method, and composite elements (And, Or, MatchFirst, Each) recursively call into their children’s parseImpl during a scan over the input string, with results.py’s ParseResults accumulating matched tokens (including named results set via .set_results_name()) as parsing proceeds; actions.py implements the parse-action callback mechanism that lets grammar authors hook into successful matches.
Tech Stack - Pure Python with no runtime dependencies, distributed with inline type stubs (py.typed) for static type checkers; the pyparsing/tools and pyparsing/diagram subpackages add optional railroad-diagram grammar visualization (built on railroad-diagrams) as an extra rather than a hard dependency, keeping the core install lightweight.
Code Quality - The library ships an explicit testing.py module with TestParseResultsAsserts-style helpers specifically to make grammars written with pyparsing easier for consumers to unit-test, on top of its own large internal test suite; exceptions.py and warnings.py provide structured parse-error reporting with line/column context rather than generic Python exceptions, which matters a lot for a parsing library’s usability.
API Design - Composing grammars via Python operator overloading (Word(alphas) + '=' + Word(nums)) is the library’s signature ergonomic choice — grammars read close to the structure they describe and stay debuggable with ordinary Python tooling (breakpoints, print statements), at some cost of operator-precedence surprises that the docs and cookbook examples work to head off.
Used by 11 apps in this directory
TDengine
Databases
A high-performance, open-source time-series database built in C for IoT, connected vehicles, and industrial monitoring workloads, with built-in stream processing, caching, and data subscription.
Weblate
Developer Tools
Continuous localization platform that commits translations directly into your version control system with full translator attribution.