parse_type

Extends the Python parse module with composable type converters and cardinality

Library
PyPI
v0.6.6
21stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
26/100Needs Attention
Development Activity0
Maintenance20
Community12
Maturity60
Momentum12

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
80/100Excellent
Architecture82
Code Quality80
Innovation80
Learning Curve76

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.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search