usaddress is a free Python library from DataMade. It parses US addresses with a trained model and runs offline. On the 24 US addresses below it got every field right. It was not trained on UK or European addresses, and on those it returns fields that look valid but are wrong.
| Every labelled field right | usaddress 0.5.16 | parseaddr |
|---|---|---|
| US addresses (24) | 24/24 | 24/24 |
| UK addresses (200) | 0/200 | 197/200 |
| Other countries (76: Canada, Australia, Germany, France, Spain, Italy and 6 more) | 3/76 | 72/76 |
| UK postcode found | 0/200 | 200/200 |
| UK city found | 102/200 | 197/200 |
Inputs, scoring script and every output: benchmarks folder.
usaddress labels every word with a US field, so a UK postcode has to become something. Raw output from usaddress.parse():
>>> usaddress.parse("14 High Street, Oxford OX1 4AG")
[('14', 'AddressNumber'), ('High', 'StreetName'), ('Street,', 'StreetNamePostType'),
('Oxford', 'OccupancyType'), ('OX1', 'OccupancyIdentifier'), ('4AG', 'OccupancyIdentifier')]
>>> usaddress.parse("14 HIGH STREET, OXFORD, OX14AG")
[..., ('OXFORD,', 'PlaceName'), ('OX14AG', 'StateName')]
>>> usaddress.parse("Hauptstraße 5, 10115 Berlin, Germany")
[('Hauptstraße', 'OccupancyType'), ('5,', 'OccupancyIdentifier'), ('10115', 'OccupancyIdentifier'),
('Berlin,', 'PlaceName'), ('Germany', 'StateName')]
In the first case the town and postcode become a flat number. In the second the postcode becomes a US state. parseaddr returns {"road": "hauptstraße", "house_number": "5", "postcode": "10115", "city": "berlin", "country": "germany"} for the third.
The 7 inputs parseaddr got wrong are listed in the benchmark: Croydon comes back as city_district, and Sydney as suburb.
import os, requests
r = requests.post(
"https://api.parseaddr.com/v1/parse",
headers={"Authorization": f"Bearer {os.environ['PARSEADDR_API_KEY']}"},
json={"address": "flat 2, 10 downing st london sw1a 2aa"},
timeout=10,
)
print(r.json()["parsed"])
# {'unit': 'flat 2', 'house_number': '10', 'road': 'downing st', 'city': 'london', 'postcode': 'sw1a 2aa'}
| usaddress label | parseaddr field |
|---|---|
AddressNumber | house_number |
StreetNamePreDirectional + StreetName + StreetNamePostType | road (one string) |
OccupancyType + OccupancyIdentifier | unit |
PlaceName | city |
StateName | state |
ZipCode | postcode |
CountryName | country |
parseaddr returns values in lower case and keeps the input's spelling: it does not expand "st" to "street" or add a space to "nw16xe". The free tier is 2,000 calls a month. See pricing for more.
parseaddr · home · agents · pricing · llms.txt · .md
Pyke Limited, registered in England and Wales, company number 09748427.