Pyap2: Address Parser

0.2.12 · active · verified Fri Apr 17

Pyap2 is a maintained fork of pyap, a regex-based library for parsing US, CA, and UK addresses. It provides a robust way to extract structured address data from unstructured text. The fork adds typing support, handles more address formats and edge cases, and is actively developed. The current version is 0.2.12, with frequent minor releases addressing new formats and edge cases.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `parse_address` with a sample US address. It's crucial to specify the `country` parameter for accurate parsing. The function returns a list of `Address` objects, from which you can extract various components or get a dictionary representation.

import pyap2

address_text = """
6162 E. Mockingbird Ln
Dallas, TX 75214
"""

# parse_address returns a list of Address objects
addresses = pyap2.parse_address(address_text, country='US')

if addresses:
    for addr in addresses:
        print(f"Parsed Address: {addr.full_address}")
        print(f"  Street: {addr.street_number} {addr.street_name} {addr.street_type}")
        print(f"  City: {addr.city}")
        print(f"  Region: {addr.region1}")
        print(f"  Postcode: {addr.postcode}")
        print(f"  As Dictionary: {addr.as_dict()}")
else:
    print("No address found or parsed.")

view raw JSON →