parse

Parse strings using a specification based on Python's format() syntax

Library
PyPI
v1.22.1
1,790stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
71/100Good
Development Activity68
Maintenance52
Community64
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
84/100Excellent
Architecture80
Code Quality84
Innovation83
Learning Curve88

parse is a Python library that does the opposite of str.format(): given a format-style pattern and an input string, it extracts the matching values, converting them to the requested types. Instead of hand-writing regular expressions, you describe the shape of your data with familiar {} and {:d}-style fields and get back a Result object with positional and named captures.

The module exposes a small, focused API — parse(), search(), findall(), and with_pattern() — plus rich format-spec type conversions for integers, floats, dates, and custom user-defined types. It is a long-standing, widely used utility for turning semi-structured text back into structured Python data.

What You Get

  • A parse() function that matches an entire string against a format pattern
  • search() to locate a pattern anywhere within a larger string
  • findall() to iterate over every occurrence of a pattern
  • Typed field conversions (:d, :f, date/time, and more) returning native Python values
  • with_pattern() to register custom, reusable field types backed by your own regex

Common Use Cases

  • Extracting fields from log lines and semi-structured text without writing regex
  • Parsing filenames or identifiers that follow a known template
  • Reading values out of formatted report or CLI output
  • Defining custom field types to validate and convert domain-specific tokens

Under The Hood

Architecture - The library is essentially a single module, parse/__init__.py (~1,100 lines), that compiles a format-style pattern into a regular expression, tracks each field’s requested type conversion, and wraps matches in a Result object exposing positional (fixed) and named captures. Parser objects can be compiled once and reused; with_pattern lets user types plug custom regex and converters into the field grammar.

Tech Stack - Pure Python with no runtime dependencies, packaged via pyproject.toml. Ships type stubs (__init__.pyi) for static analysis and a check_typing.py helper.

Code Quality - The project is mature and actively maintained, with a broad pytest suite (tests/) split across parsing, searching, findall, result handling, pattern edge cases, and regression bugs, plus typing checks. Nearly all behavior is exercised by tests.

API Design - The public surface is deliberately tiny and mirrors str.format() one-to-one, so anyone who knows format strings can use it immediately. Compiled Parser reuse and with_pattern extensibility cover advanced needs without complicating the basic calls.

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