Replacing parse (migration)

formatparse aims to be a drop-in replacement for the original parse package for common uses, with a Rust-backed implementation for speed.

API surface

Import parse(), search(), findall(), compile(), with_pattern(), and result types from the formatparse package the same way you would from parse. formatparse adds optional features (validators, :ml / :blk, nested specs, composed_type, findall_iter, parse_batch, and more) documented elsewhere in this guide.

Malformed patterns

For some invalid patterns (for example a missing } after a field), parse() returns None while compile() raises PatternParseMismatch (a subclass of ValueError). Other syntax errors may still raise plain ValueError from both APIs—this mirrors the original parse library.

Pattern cache and extra_types

parse, search, findall, and compile share an internal LRU cache keyed by the pattern string and a fingerprint of extra_types (each converter’s pattern and regex_group_count). If you change a converter’s pattern at runtime without changing the dict object identity, you can still hit a stale cache entry—use a fresh extra_types dict or restart the process. See issue #29.

Pickling

Pickling a FormatParser stores only the pattern string. After pickle.loads, pass extra_types again when parsing if your pattern uses custom types.