{"id":10078,"library":"pyap2","title":"Pyap2: Address Parser","description":"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.","status":"active","version":"0.2.12","language":"en","source_language":"en","source_url":"https://github.com/argyle-engineering/pyap","tags":["address parsing","regex","geocoding","data cleaning","text processing"],"install":[{"cmd":"pip install pyap2","lang":"bash","label":"Install pyap2"}],"dependencies":[],"imports":[{"note":"Pyap2 is a fork of pyap; ensure you import from the correct package name (pyap2, not pyap) if you are migrating or specifically using the fork.","wrong":"from pyap import parse_address","symbol":"parse_address","correct":"from pyap2 import parse_address"}],"quickstart":{"code":"import pyap2\n\naddress_text = \"\"\"\n6162 E. Mockingbird Ln\nDallas, TX 75214\n\"\"\"\n\n# parse_address returns a list of Address objects\naddresses = pyap2.parse_address(address_text, country='US')\n\nif addresses:\n    for addr in addresses:\n        print(f\"Parsed Address: {addr.full_address}\")\n        print(f\"  Street: {addr.street_number} {addr.street_name} {addr.street_type}\")\n        print(f\"  City: {addr.city}\")\n        print(f\"  Region: {addr.region1}\")\n        print(f\"  Postcode: {addr.postcode}\")\n        print(f\"  As Dictionary: {addr.as_dict()}\")\nelse:\n    print(\"No address found or parsed.\")","lang":"python","description":"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."},"warnings":[{"fix":"Ensure you install `pyap2` and update your import statements to `from pyap2 import parse_address`.","message":"Pyap2 is a maintained fork of the original `pyap` library. If migrating from `pyap`, you must change your package installation (`pip install pyap2`) and all import statements from `from pyap import ...` to `from pyap2 import ...`.","severity":"breaking","affected_versions":"All versions"},{"fix":"When processing text with multiple addresses, ensure each distinct address is on its own line or separated by newlines.","message":"The `parse_address` function relies on regex and is highly sensitive to the input address format. For multiple addresses within a single string, each address must be separated by a newline to be parsed correctly. Otherwise, they might be treated as a single, malformed address.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always pass the appropriate `country` parameter (e.g., 'US', 'CA', 'UK') to `parse_address`.","message":"The `country` parameter in `parse_address` is critical for accurate results. Failing to specify it, or providing an incorrect country, can lead to no addresses being found or incorrect parsing, as the regex patterns are country-specific.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Verify that the addresses you intend to parse are from one of the supported countries. For other regions, consider alternative libraries.","message":"Pyap2 currently only supports address parsing for the United States (US), Canada (CA), and the United Kingdom (UK). Addresses from other countries will not be parsed correctly, or at all.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"If you intend to use `pyap2`, ensure you run `pip install pyap2` and change all imports to `from pyap2 import ...`. If you intend to use the original `pyap`, run `pip install pyap` and use `from pyap import ...`.","cause":"You are trying to import from the original `pyap` package, but you have installed `pyap2` (the fork) or vice-versa, or neither is installed.","error":"ModuleNotFoundError: No module named 'pyap'"},{"fix":"Always check if the returned list is not empty before attempting to access elements, e.g., `addresses = pyap2.parse_address(...)` then `if addresses: first_address = addresses[0]`.","cause":"`pyap2.parse_address` returns an empty list when no addresses are found in the input string, and you're trying to access an element from an empty list.","error":"IndexError: list index out of range (when trying to access addresses[0])"},{"fix":"Ensure you provide the correct `country` parameter (e.g., `country='US'`) corresponding to the address you are trying to parse.","cause":"This is often caused by an incorrect or missing `country` parameter, which results in the regex patterns not matching correctly for the given address locale.","error":"No addresses found (empty list returned) even for a seemingly valid address."},{"fix":"Insert newline characters (\\n) between each distinct address in your input string. For example: `address_string = '123 Main St, Anytown, US\\n456 Oak Ave, Otherville, US'`.","cause":"The parser needs explicit newlines to distinguish between separate addresses within a single input string.","error":"Multiple addresses in a string are being parsed as a single, incorrect address."}]}