parse_type
Extends the Python parse module with composable type converters and cardinality
Repository Health
Technical Analysis
parse_type builds on the popular parse module (the opposite of str.format()) by making it easy to construct and compose custom type converters. It provides helpers to turn enums, mappings, and fixed choices into parse-compatible converters, and to combine existing converters into new ones without hand-writing regular expressions.
Its signature feature is cardinality: from a single type converter for one value, parse_type can automatically derive optional (0..1), many (0..), and one-or-more (1..) variants, and an extended parser recognizes a CardinalityField naming scheme to wire these variants in automatically. This makes it a natural companion for tools like behave that lean heavily on the parse type system.
What You Get
- Builder helpers to create enum/mapping and choice type converters
- Composition of new type converters from existing ones
- Automatic generation of cardinality variants (0..1, 0.., 1..) from a base converter
- An extended CardinalityField parser that wires missing variants automatically
- Drop-in compatibility with the parse module’s type-converter conventions
Common Use Cases
- Defining reusable enum and choice parsers for behave step definitions
- Parsing lists of values with a single base converter plus cardinality
- Composing complex field converters from simpler building blocks
- Extending parse-based grammars without writing raw regular expressions
Under The Hood
Architecture - The parse_type package centers on builder.py (the TypeBuilder that creates enum/mapping, choice, and composed converters), cardinality.py and cardinality_field.py (deriving and naming 0..1 / 0..* / 1..* variants), and cfparse.py (a Parser subclass that recognizes the CardinalityField naming scheme and auto-creates missing variants). Utilities live in parse_util.py.
Tech Stack - Pure Python built as a thin extension layer over the parse module, packaged with setuptools (setup.py/pyproject.toml). Development uses tox, pytest, invoke, and just for task running.
Code Quality - A mature, stable library with an extensive pytest suite under tests/, including cardinality, builder, and CardinalityField coverage plus vendored parse test suites. Community activity is small and releases are infrequent, but the API is settled and the tests are thorough.
API Design - The TypeBuilder API reads declaratively (TypeBuilder.make_enum, make_choice, with_cardinality), and the cardinality field naming convention removes boilerplate by generating related converters from one definition, keeping user grammars concise.
Used by 2 apps in this directory
Memgraph
Databases · AI Development
High-performance in-memory graph database for AI context and real-time analytics
Stirling PDF
Productivity · Digital Signiture
The open-source PDF platform you can run anywhere — edit, convert, sign, and automate PDFs without sending files to external servers.