Install & Compatibility
Where this runs
tested against v0.26.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
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.038s · 17.8MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 1.5s · import 0.034s · 18MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Parser
✓ from textparser import Parser
Primary class for defining a parser.
Sequence
✓ from textparser import Sequence
Commonly used grammar element for sequential patterns.
This 'Hello World' example demonstrates how to define a custom parser by subclassing `textparser.Parser`. It specifies token types with regular expressions in `token_specs` and defines a simple grammar using `textparser.Sequence` in `grammar` to parse the string 'Hello, World!' into a parse tree.
import textparser
from textparser import Sequence
class MyParser(textparser.Parser):
def token_specs(self):
return [
('SKIP', r'[ \r\n\t]+'),
('WORD', r'\w+'),
('EMARK', '!', r'!'),
('COMMA', ',', r','),
('MISMATCH', r'.')
]
def grammar(self):
return Sequence('WORD', ',', 'WORD', '!')
tree = MyParser().parse('Hello, World!')
print('Tree:', tree)
# Expected output: Tree: ['Hello', ',', 'World', '!']
Debug
Known issues
gotchaWhen defining token specifications with `(kind, name, re)`, ensure the `grammar` refers to the `name` instead of the `kind`. Using `kind` when `name` is provided will lead to parsing errors.fixIf `token_specs` contains `('TYPE', 'friendly_name', r'regex')`, then `grammar` patterns should reference `'friendly_name'` not `'TYPE'`. affects: All versions
gotchaThe structure of parse trees returned by `textparser` can vary, and additional post-processing may be required to fit specific application needs. Its primary goal is speed, not necessarily a universally consistent parse tree format across different grammars.fixAlways inspect the output parse tree for your specific grammar and implement any necessary transformations or validations on the returned structure.
affects: All versions
gotchaThe library's last release was April 2022, indicating a slower development pace. While generally stable, users should be aware of potential future compatibility challenges with newer Python versions or lack of updates for new parsing paradigms.fixMonitor the GitHub repository for updates. Test thoroughly with new Python versions or complex scenarios before deploying in production environments. Consider contributing if specific features or fixes are needed.
affects: 0.24.0 and older
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'textparser'
The 'textparser' library has not been installed in the current Python environment.
fixRun `pip install textparser` to install the library.
sre_constants.error: nothing to repeat at position 0
An invalid regular expression pattern was provided when defining a `textparser.tokens.Token`, often by starting a pattern with a quantifier like `*` or `+`.
fixEnsure the regular expression pattern is valid. For example, quantifiers like `*` or `+` cannot appear at the beginning of a pattern without a preceding element to quantify.
KeyError: "Rule 'UNDEFINED_RULE' is not defined"
A grammar rule defined within a `textparser.grammar.Grammar` class refers to another rule or token that has not been defined in the grammar or lexer's token set.
fixEnsure all referenced rules and tokens are properly defined within the `Grammar` class or provided to the `Lexer`.
AttributeError: module 'textparser' has no attribute 'parse'
The `parse` method is not directly available on the `textparser` module. It is a method of a `textparser.grammar.Grammar` instance, which must be created first.
fixInstantiate a `textparser.grammar.Grammar` class with a `textparser.lexers.Lexer` instance, then call the `parse()` method on that grammar object.
Upgrade
Version history
0.26.2latest on PyPI · released Jun 20, 2026
Audit
Dependencies
No dependency data recorded yet.