flexparser
Parsing made fun ... using typing.
What it is and what it does
flexparser is a parser framework that lets you define custom statement types as frozen dataclasses with a `from_string` classmethod. Instead of writing a traditional recursive-descent or grammar-based parser, you write one class per statement type and the framework handles iteration, error collection, and file I/O. Each parsed statement is automatically annotated with line and column positions, raw text, and a content hash.
The framework distinguishes between statements the parser doesn't recognize (returns None), valid statements, and parsing errors (subclasses of ParsingError). It also supports grouping statements into blocks with begin/end markers. The result is a sequence of typed objects you can iterate over, making downstream processing type-safe and straightforward. It depends only on typing-extensions and requires Python 3.9 or later.
Use it for:
- Parse domain-specific languages or configuration formats where each line type maps to a distinct dataclass.
- Build error-tolerant parsers that collect all parsing failures and continue, reporting them at the end.
- Parse structured text files (logs, reports, DSLs) where you want position tracking and type safety without writing a grammar.
- Validate and extract data from line-oriented text where different line patterns need different handling logic.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
flexparser lets you build parsers by writing dataclasses with a `from_string` method, automatically handling file parsing, error reporting, and structured output with type safety.
Yes, if you need a lightweight, type-safe parser for line-oriented text and don't require active maintenance. The low dependency footprint and permissive license make it a reasonable choice for small-to-medium parsing tasks. The dormant status means no new features or bug fixes are likely, so evaluate whether the current API and behavior meet your needs before committing.
Install
flexparser on PyPI
pip
pip install flexparseruv
uv add flexparserpoetry
poetry add flexparserInstalling flexparser
Before you install
Low friction: pure Python wheel with only typing-extensions as a runtime dependency. Maintenance is dormant—last release was 2024-11-07 and last commit 2024-11-09, with no recent activity; the package is stable but not actively developed.
License in practice
BSD-3-Clause is permissive and imposes no significant restrictions on use or redistribution, making it suitable for most commercial and open-source projects.
Quickstart
pip install flexparser
from dataclasses import dataclass
import flexparser as fp
@dataclass(frozen=True)
class Assignment(fp.ParsedStatement):
lhs: str
rhs: str
@classmethod
def from_string(cls, s):
if "<-" not in s:
return None
lhs, rhs = s.split("<-")
return cls(lhs.strip(), rhs.strip())
parsed = fp.parse("file.txt", Assignment)
for statement in parsed.iter_statements():
print(statement)
Verify before relying
- Whether the package handles nested or recursive block structures beyond the single-level Block example shown.
- Performance characteristics when parsing large files or deeply nested structures.
- Whether custom error recovery or partial parsing is supported beyond returning None or a ParsingError.
Package facts
| License | BSD-3-Clause (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — typing-extensions |
| Maintenance | dormant — 645 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 5,716,000/month — #2,046 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: flexparser-0.4-py3-none-any.whl
Keywords: parser, code, parsing, source
Tags
More Libraries packages
urllib3 is an HTTP client library that provides…
permissive · top 100 on PyPI
requestsRequests is a Python HTTP library that…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
python-dateutilProvides parsing, arithmetic, and recurrence…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
construct-classesParses binary data into Python dataclasses and…
permissive · top 15,000 on PyPI
argparse-dataclassBuilds command-line interfaces declaratively by…
permissive · top 5,000 on PyPI
databindDatabind deserializes JSON-like nested data…
permissive · top 15,000 on PyPI
simple-parsingTransforms argparse scripts into structured,…
permissive · top 5,000 on PyPI
rplyRPLY is a pure Python parser generator that…
permissive · top 15,000 on PyPI
dataclass-factoryConverts dataclasses to and from dictionaries…
permissive · top 15,000 on PyPI
daciteConverts dictionaries into dataclass instances…
permissive · top 1,000 on PyPI
databind.jsonDeserializes and serializes Python dataclasses…
permissive · top 15,000 on PyPI
typed-json-dataclassAdds JSON serialization and type validation to…
permissive · top 15,000 on PyPI
dataclassesProvides the PEP 557 dataclasses module for…
permissive · top 5,000 on PyPI