API reference

Everything public in petrock, version 2.4.1.

parse(text, country=None, strict=False)

Parses a single address string and returns an Address. Raises petrock.ParseError only when strict=True and no field could be assigned; otherwise it returns a low-confidence result.

ArgumentTypeDefaultMeaning
textstrRaw address. Newlines and repeated whitespace are collapsed.
countrystr | NoneNoneISO 3166-1 alpha-2, lowercase. None triggers detection.
strictboolFalseRaise instead of returning a partial result.

parse_many(rows, country=None, workers=1)

Generator yielding (source, Address) pairs in input order. With workers > 1 the work is split across processes; ordering is still preserved, at the cost of buffering up to workers × 512 results.

Address

FieldTypeNotes
streetstrTitle-cased, abbreviations expanded (ul.Ulica).
numberstrKept as a string — descriptive/orientation pairs like 1149/7 must not be split.
postcodestrDigits only, no spaces, left-padded where the country uses fixed width.
localitystrCity or municipality.
districtstr | NoneSet only where the country’s rule set defines one.
countrystrResolved country code, even when it was detected.
confidencefloatShare of input tokens assigned to a field.
rawstrThe original input, unmodified.

Address.as_dict()

Returns a plain dict with the fields above. Stable across minor versions — new fields may be added, existing ones are never renamed inside a major version.

Exceptions

ClassRaised when
ParseErrorstrict=True and nothing could be assigned.
UnknownCountryA country code has no rule set.
RuleTableErrorThe bundled table is missing or corrupt — reinstall.
All exceptions inherit from petrock.PetrockError, so a single except is enough if you do not care which one fired.