USaddress is a Python library designed for parsing unstructured United States address strings into their individual components, employing advanced Natural Language Processing (NLP) methods. It utilizes a probabilistic model, specifically Conditional Random Fields, to make educated guesses in identifying address parts, even in complex cases. The library's current version is 0.5.16, and it is actively maintained.
pip install usaddressVerified import paths — ran on the pinned version, not inferred.
This example demonstrates both the `parse()` method, which returns a list of (value, label) tuples, and the `tag()` method, which returns a more structured `OrderedDict` of components and an inferred address type.
Catch `RepeatedLabelError` when using `tag()` and consider using `parse()` for more granular (though less aggregated) output, or preprocess ambiguous input strings.
Ensure input addresses are strictly within the United States. For international address parsing, use a library specifically designed for global addresses (e.g., libpostal Python bindings).
Do not rely on usaddress for address validation. For validation, integrate with a dedicated address verification service (e.g., USPS API, SmartyStreets, etc.) after parsing with usaddress.
Install the library using pip: `pip install usaddress`
Reinstall 'usaddress' to ensure all model dependencies are correctly placed: `pip uninstall usaddress && pip install usaddress`
Ensure the input passed to `usaddress.tag()` is a valid string: `usaddress.tag(str(my_variable))` or validate input: `if isinstance(my_variable, str): usaddress.tag(my_variable)`
Use the correct function name `usaddress.tag()` or its alias `usaddress.parse()` to parse an address string.