Registry / serialization / pypeg2

pypeg2

JSON →
library2.15.2pypypi✓ verified 93d ago

An intrinsic PEG Parser-Interpreter for Python, providing a simple way to define grammars using Python classes. Current version 2.15.2; no regular release cadence.

pip install pypeg2
INSTALL
IMPORT
SIG · PYPEG2
P
pypeg2
serializationpythonv2.15.2
Install
2.4s avg
Import
10ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v2.15.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.006s · 19.4MB
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 2.4s · import 0.006s · 20MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Parser
✓ from pypeg2 import Parser
correct import path
Symbol
✓ from pypeg2 import Symbol
correct import path
Keyword
✓ from pypeg2 import Keyword
correct import path
Namespace
✓ from pypeg2 import Namespace
correct import path
attr
✓ from pypeg2 import attr
correct import path
parse
✓ from pypeg2 import parse
correct import path

Define a simple grammar with classes and parse a string.

from pypeg2 import Symbol, Keyword, attr, parse class Name(Symbol): grammar = attr('first', str), attr('last', str) class Greeting(Keyword): grammar = 'hello' class Sentence: grammar = Greeting, Name result = parse('hello John Doe', Sentence) print(result.greeting, result.name.first, result.name.last)
Debug
Known issues
gotchaPyPEG2 uses Python's `str` as a base class for `Symbol`, which means that parsed values become strings. Be careful with type checks and comparisons.
fix
Use the parsed object's attributes directly; do not rely on type identity.
affects: all
deprecatedThe `pypeg2` library is not actively maintained and may have compatibility issues with newer Python versions (e.g., Python 3.10+).
fix
Consider using alternative PEG parser generators like `parsimonious` or `lark-parser` for new projects.
affects: 2.15.2
gotchaGrammar definitions using tuples and `attr` can be confusing. Order of elements in tuple matters for parsing sequence.
fix
Always use `attr` to define fields; the order of tuple elements defines the parse order.
affects: all
Errors
Common errors & fixes
AttributeError: module 'pypeg2' has no attribute 'parse'
Incorrect import; installed `pypeg` instead of `pypeg2`.
fix
Install correct package: `pip install pypeg2` and use `from pypeg2 import parse`.
TypeError: 'Symbol' object does not support indexing
Treating a parsed `Symbol` as a tuple/list instead of accessing its attributes.
fix
Parse result is an object with attributes; use dot notation like `result.name.first`.
ImportError: cannot import name 'Parser' from 'pypeg2'
Typo in import; correct symbol is `Parser` but some older documentation shows `parser` (lowercase).
fix
Use correct import: `from pypeg2 import Parser` (capital P).
Upgrade
Version history
2.15.2latest on PyPI · released Oct 7, 2015
Audit
Dependencies

No dependency data recorded yet.

Agent activity
11 hits · last 30 days
node
10
Resources
pypeg2 — pip install pypeg2 · libregistry