Skip to main content

Parse strings using a specification based on the Python format() syntax (Rust implementation)

Project description

formatparse

PyPI version Python 3.8+ License: MIT Rust Documentation

A high-performance, Rust-backed implementation of the parse library for Python. formatparse provides the same API as the original parse library but with significant performance improvements (up to 80x faster) thanks to Rust's zero-cost abstractions and optimized regex engine.

📖 Documentation

Full documentation is available at https://formatparse.readthedocs.io/

The documentation includes:

  • Getting Started Guide - Quick introduction and basic usage
  • User Guides - Comprehensive guides on patterns, datetime parsing, custom types, and bidirectional patterns
  • API Reference - Complete API documentation for all functions and classes
  • Examples & Cookbook - Practical examples and common use cases
  • Changelog - Release history in CHANGELOG.md in the repository

Features

  • 🚀 Blazing Fast: Up to 80x faster than the original Python implementation
  • 🔄 Drop-in Replacement: Compatible API with the original parse library
  • 🎯 Type-Safe: Rust backend ensures reliability and correctness
  • 🔍 Advanced Pattern Matching: Support for named fields, positional fields, and custom types
  • 📅 DateTime Parsing: Built-in support for various datetime formats (ISO 8601, RFC 2822, HTTP dates, etc.)
  • 🎨 Flexible: Case-sensitive and case-insensitive matching options
  • 💾 Optimized: Pattern caching, lazy evaluation, and batch operations for maximum performance

Installation

From PyPI

pip install formatparse

From Source

# Clone the repository
git clone https://github.com/eddiethedean/formatparse.git
cd formatparse

# Install maturin (build tool)
pip install maturin

# Build and install in development mode
maturin develop --manifest-path formatparse-pyo3/Cargo.toml --release

Quick Start

from formatparse import parse, search, findall

# Basic parsing with named fields
result = parse("{name}: {age:d}", "Alice: 30")
print(result.named['name'])  # 'Alice'
print(result.named['age'])   # 30

# Search for patterns in text
result = search("age: {age:d}", "Name: Alice, age: 30, City: NYC")
if result:
    print(result.named['age'])  # 30

# Find all matches
results = findall("ID:{id:d}", "ID:1 ID:2 ID:3")
for result in results:
    print(result.named['id'])
# Output: 1, 2, 3

For more examples and detailed usage, see the documentation.

Performance

formatparse is significantly faster than the original Python parse library, with speedups ranging from 3x to 80x depending on the use case. The Rust backend provides:

  • Pattern caching to eliminate regex compilation overhead
  • Optimized type conversion paths for common types
  • Efficient memory management with pre-allocated data structures
  • Reduced Python GIL overhead through batched operations

For detailed benchmark results and performance analysis, see the documentation.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

For detailed contribution guidelines, including testing requirements and development setup, see CONTRIBUTING.md.

Testing

The project includes comprehensive test coverage:

  • Unit Tests: ~436 Python tests + 50 Rust tests
  • Property-Based Tests: 32 Hypothesis-based tests
  • Performance Benchmarks: Automated regression testing
  • Stress Tests: Large input and scalability testing
  • Fuzz Tests: Crash-free input testing
  • Coverage: >90% code coverage target

Run tests with:

# All tests
pytest tests/

# With coverage
pytest tests/ --cov=formatparse --cov-report=html

# Benchmarks
pytest tests/test_performance.py --benchmark-only

See CONTRIBUTING.md for more testing information.

License

MIT License - see LICENSE file for details

Credits

Based on the parse library by Richard Jones.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

formatparse-0.7.0.tar.gz (71.4 kB view details)

Uploaded Source

File details

Details for the file formatparse-0.7.0.tar.gz.

File metadata

  • Download URL: formatparse-0.7.0.tar.gz
  • Upload date:
  • Size: 71.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for formatparse-0.7.0.tar.gz
Algorithm Hash digest
SHA256 c964343eda1f740578bff8b21bfb49f21e692b3d960dee76611edcd826f96a7e
MD5 c4b936fd17e86e5fb58901e45f227d32
BLAKE2b-256 ea0aeba3f7515531557149be56e4ad862af918adf7b0dc0b47faabd9cfbb010a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page