formatparse
A Rust-backed reimplementation of the parse library for Python. It targets the same parse / search / findall workflow with substantially lower overhead on hot paths (performance guide). Use it as a drop-in replacement for common parse patterns; see the migration guide for edge-case differences.
Documentation
Full documentation: https://formatparse.readthedocs.io/
- Getting Started
- User Guides — patterns, datetime, custom types, validation, security
- API Reference
- FAQ / Troubleshooting
- Security — read before parsing untrusted input
- Changelog
Features
- Fast: Rust backend with pattern caching and batch APIs (benchmarks)
- Drop-in replacement: Compatible with common
parseusage (migration guide) - Pattern matching: Named and positional fields, custom types, nested specs
- DateTime parsing: ISO 8601, log timestamps, strftime, and more
- Case-sensitive and case-insensitive matching (matching behavior)
- Validation and bidirectional patterns for round-trip format/parse workflows
Installation
pip install formatparse
From source, see Installation in the docs.
Quick Start
from formatparse import parse, search, findall
result = parse("{name}: {age:d}", "Alice: 30")
print(result.named["name"], result.named["age"]) # Alice 30
More examples: Getting Started.
Malformed patterns: parse vs compile
For some invalid patterns (for example a missing } after a field), parse returns None while compile raises PatternParseMismatch. See the migration guide.
Custom types (extra_types)
Use @with_pattern and an extra_types dict — see the Custom types guide. Caching and pickling notes are documented there and in FAQ.
Contributing
See CONTRIBUTING.md and the Contributing docs page.
Testing
- Python: 740+ tests (
pytest tests/), coverage enforced at 86%+ in CI - Rust:
formatparse-coreandformatparse-pyo3tests (cargo test -p formatparse-core --all-targets)
export PYTEST_DISABLE_PLUGIN_AUTOLOAD=1
pytest tests/
License
MIT License — see LICENSE.
Credits
Based on the parse library by Richard Jones.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file formatparse-0.8.7.tar.gz.
File metadata
- Download URL: formatparse-0.8.7.tar.gz
- Upload date:
- Size: 103.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a427d4e0771e3a032324e8c0b4bd3608d84b08685b580446bede7d2a733191df
|
|
| MD5 |
90c51e45ae5cfd40cd7a32cb6e0cd5e3
|
|
| BLAKE2b-256 |
5c0821439da10b6570662d481514c20ead0ad4cce32f54f917be868b740a8bb6
|