Registry / serialization / mo-parsing

mo-parsing

JSON →
library8.694.25301pypypi✓ verified 85d ago

mo-parsing is a Python PEG (Parsing Expression Grammar) parsing tool. It is a fork of `pyparsing`, designed for faster parsing, and allows users to define parsers using predefined patterns and Python operators. The library is currently at version 8.694.25301, with its latest release uploaded on October 27, 2025 (likely 2024, indicating active development with frequent updates).

pip install mo-parsing
INSTALL
IMPORT
SIG · MO-PARSING
M
mo-parsing
serializationpythonv8.694.25301
Install
1.8s avg
Import
175ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v8.694.25301 · 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.910 runs
installs and imports cleanly · install 0.0s · import 0.181s · 18.6MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 1.8s · import 0.168s · 19MB
17MB installed
● package 17MB
Code
Verified usage

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

Word
from mo_parsing import Word
Literal
from mo_parsing import Literal
Keyword
from mo_parsing import Keyword
Group
from mo_parsing import Group
Regex
from mo_parsing import Regex
alphas
from mo_parsing.utils import alphas
Whitespace
from mo_parsing.whitespaces import Whitespace
from mo_parsing import Whitespace
Whitespace context manager is in its own submodule.

This quickstart demonstrates defining a simple grammar using `Word` and `Literal`, managing whitespace with `Whitespace` context, and parsing a string. It shows how to access the parsed results as both a list and a dictionary.

from mo_parsing import Word, Literal from mo_parsing.utils import alphas from mo_parsing.whitespaces import Whitespace # Define a simple grammar for 'Hello, World!' with a custom whitespace rule with Whitespace(' \t') as whitespace_context: greet = Word(alphas)('greeting') + Literal(',') + Word(alphas)('person') + Literal('!') # Parse a string result = greet.parse_string('Hello, World!') # Access results as a list print(f"List view: {list(result)}") # Access results as a dictionary (for named tokens) print(f"Dict view: {dict(result)}") # Example with different input result_named = greet.parse_string('Hi, There!') print(f"Named tokens: {result_named.greeting}, {result_named.person}")
Debug
Known issues
breakingParserElements are static. Methods like `.add_parse_action(action)` create and return a *new* ParserElement. If the result is not assigned back to a variable, the parse action (or any other modification) will be lost.
fix
Always reassign the result of methods that modify ParserElements: `my_parser = my_parser.add_parse_action(my_action)`
affects: All versions (since fork from pyparsing)
breakingWhitespace handling has been refactored. `mo-parsing` uses the `mo_parsing.whitespaces.Whitespace` context manager to define ignored characters, replacing `pyparsing`'s global `whitespace_chars` or `parser.set_whitespace_chars()` methods, which are removed.
fix
Use the `with Whitespace(...) as context:` block or `Whitespace().use()` for language definition.
affects: All versions (since fork from pyparsing)
gotchaThe parameter order for parse actions is `(tokens, index, string)`, which is the opposite of `pyparsing`'s `(string, location, tokens)`.
fix
Adjust your parse action signatures to `def my_action(tokens, loc, string):` or `lambda t, l, s: ...`
affects: All versions (since fork from pyparsing)
gotchaDo not confuse `Word()`, `Literal()`, and `Keyword()` for exact string matching. `Word(string_of_characters)` matches any contiguous sequence of *characters found within* `string_of_characters`, not the exact `string_of_characters` itself.
fix
Use `Literal('exact string')` for a fixed string match, or `Keyword('exact word')` for a fixed string that must be a whole word (with word boundaries).
affects: All versions (inherited from pyparsing behavior)
Errors
Common errors & fixes
TypeError: 'NoneType' object is not callable (when a parse action doesn't seem to run)
You likely applied a parse action to a ParserElement without reassigning the result, e.g., `some_parser.add_parse_action(my_func)` instead of `some_parser = some_parser.add_parse_action(my_func)`.
fix
Remember that `ParserElement` methods like `add_parse_action` return a *new* ParserElement object. Always assign the result back to the variable: `my_parser = my_parser.add_parse_action(my_func)`.
mo_parsing.exceptions.ParseException: Expected 'something_else' (when parser consumes too much or wrong input)
A common cause is misusing `Word(chars)` where `Literal(exact_string)` or `Keyword(exact_word)` was intended. `Word('abc')` will match 'apple', 'banana', 'cat' because 'a', 'b', 'c' are in its character set, not just 'abc'.
fix
If you need to match a specific string exactly, use `Literal('your_string')`. If it must be a whole word, use `Keyword('your_word')`.
mo_parsing.exceptions.ParseException: Expected ... (when trying to match a literal phrase with spaces)
Using `Literal('multiple words')` will attempt to match the entire string literally, including spaces, without allowing for intervening whitespace skipping behavior.
fix
For phrases with spaces that should allow for arbitrary whitespace (and comments if configured), split them into separate `Literal` or `Keyword` elements: `Literal('first') + Literal('second')`.
Upgrade
Version history
8.694.25301latest on PyPI · released Oct 28, 2025
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
mo-parsing — pip install mo-parsing · libregistry