Registry / serialization / parsley

parsley

JSON →
library1.3pypypi✓ verified 23d ago

Parsley is a Python parsing library designed to simplify parsing and pattern matching. It implements the Parsing Expression Grammar (PEG) algorithm, compiling grammar definitions into Python classes where rules become methods. This approach aims to make parsing expressions behave similarly to standard Python expressions. It is an implementation of OMeta, an object-oriented pattern-matching language. The current version is 1.3, released in 2017.

pip install parsley
INSTALL
IMPORT
SIG · PARSLEY
P
parsley
serializationpythonv1.3
Install
1.6s avg
Import
26ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.3 · 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.103.95 runs
installs and imports cleanly · install 0.0s · import 0.028s · 18.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.024s · 19MB
17MB installed
● package 17MB
Code
Verified usage

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

makeGrammar
from parsley import makeGrammar
import parsley parser_class = parsley.makeGrammar(grammar_source, bindings)

This quickstart defines a simple grammar for basic arithmetic (addition, multiplication, and integers). It demonstrates how to create a grammar, instantiate a parser with input, and execute a rule to get the result. Note the use of `-> int(ds)` to convert matched digit strings to integers and `-> left + right` for performing calculations within the grammar itself.

import parsley grammar_source = """ integer = <digit+>:ds -> int(ds) sum = integer:left '+' integer:right -> left + right product = integer:left '*' integer:right -> left * right expression = sum | product | integer """ calculator_grammar = parsley.makeGrammar(grammar_source, {}) # Parse a sum parser_sum = calculator_grammar("10+20") result_sum = parser_sum.sum() print(f"10+20 = {result_sum}") # Expected: 30 # Parse a product parser_product = calculator_grammar("5*6") result_product = parser_product.product() print(f"5*6 = {result_product}") # Expected: 30 # Parse a single integer parser_int = calculator_grammar("123") result_int = parser_int.integer() print(f"123 = {result_int}") # Expected: 123
Debug
Known issues
breakingThe Parsley project has seen no new releases since version 1.3 in April 2017, and its GitHub repository shows no recent activity. This indicates the project is effectively abandoned, meaning no new features, bug fixes, security updates, or official support for newer Python versions should be expected.
fix
Consider migrating to actively maintained parsing libraries such as `lark`, `pyparsing`, or `parsy` for projects requiring ongoing support and compatibility with modern Python environments.
affects: All versions (due to lack of future maintenance)
gotchaParsley's PEG (Parsing Expression Grammar) parser evaluates alternatives (`|`) strictly in order, unlike traditional LL/LR parsers (e.g., Yacc, PLY) which might use longest match or other lookahead strategies. This can lead to unexpected parsing results if the order of alternatives is not carefully considered, as an earlier, less specific rule might consume input that a later, more specific rule was intended to handle.
fix
Always place more specific or 'longer' matching rules before more general or 'shorter' matching rules when using alternatives (`|`) to ensure the desired rule is matched first.
affects: All versions
gotchaAlthough some community efforts (e.g., operating system packages) exist for Python 3 compatibility, the last official release of Parsley (v1.3 in 2017) pre-dates broad adoption and dedicated testing for recent Python 3.x versions. Users might encounter subtle compatibility issues, unaddressed bugs, or missing features when running Parsley on modern Python 3.8+ environments.
fix
Thoroughly test Parsley-based parsers on your target Python 3.x environment. Be prepared to fix potential compatibility issues or consider alternatives for new projects.
affects: All versions, especially with Python 3.8+
gotchaWhen using repetition operators (`*` for zero or more, `+` for one or more) with rules that incorporate Python actions (`-> pythonExpression`) for transformation or aggregation, results from chained matches may overwrite previous results instead of accumulating into a list. Parsley does not automatically manage list accumulation in all such scenarios.
fix
Explicitly manage list accumulation or aggregation within your Python actions. For example, collect intermediate results into a list and return the final list from a rule, or use helper functions bound to the grammar.
affects: All versions
Upgrade
Version history
1.3latest on PyPI · released Sep 9, 2015
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
Resources