parse
Parse strings using a specification based on Python's format() syntax
Repository Health
Technical Analysis
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.
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.