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
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.028s · 18.9MB
glibcpy 3.10–3.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.fixConsider 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.fixAlways 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.fixThoroughly 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.fixExplicitly 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.