Skip to main content

Parse US addresses using conditional random fields

Project description

usaddress

usaddress is a Python library for parsing unstructured United States address strings into address components, using advanced NLP methods.

What this can do: Using a probabilistic model, it makes (very educated) guesses in identifying address components, even in tricky cases where rule-based parsers typically break down.

What this cannot do: It cannot identify address components with perfect accuracy, nor can it verify that a given address is correct/valid.

It also does not normalize the address. However, this library built on top of usaddress does.

Tools built with usaddress

Parserator API

A RESTful API built on top of usaddress for programmers who don't use python. Requires an API key and the first 1,000 parses are free.

Parserator Google Sheets App

Parserator: Parse and Split Addresses allows you to easily split addresses into separate columns by street, city, state, zipcode and more right in Google Sheets.

How to use the usaddress python library

  1. Install usaddress with pip, a tool for installing and managing python packages (beginner's guide here).

In the terminal,

pip install usaddress
  1. Parse some addresses!

usaddress

Note that parse and tag are different methods:

import usaddress
addr='123 Main St. Suite 100 Chicago, IL'

# The parse method will split your address string into components, and label each component.
# expected output: [(u'123', 'AddressNumber'), (u'Main', 'StreetName'), (u'St.', 'StreetNamePostType'), (u'Suite', 'OccupancyType'), (u'100', 'OccupancyIdentifier'), (u'Chicago,', 'PlaceName'), (u'IL', 'StateName')]
usaddress.parse(addr)

# The tag method will try to be a little smarter
# it will merge consecutive components, strip commas, & return an address type
# expected output: (OrderedDict([('AddressNumber', u'123'), ('StreetName', u'Main'), ('StreetNamePostType', u'St.'), ('OccupancyType', u'Suite'), ('OccupancyIdentifier', u'100'), ('PlaceName', u'Chicago'), ('StateName', u'IL')]), 'Street Address')
usaddress.tag(addr)

How to use this development code (for the nerds)

usaddress uses parserator, a library for making and improving probabilistic parsers - specifically, parsers that use python-crfsuite's implementation of conditional random fields. Parserator allows you to train the usaddress parser's model (a .crfsuite settings file) on labeled training data, and provides tools for adding new labeled training data.

Building & testing the code in this repo

To build a development version of usaddress on your machine, run the following code in your command line:

git clone https://github.com/datamade/usaddress.git  
cd usaddress  
pip install -e ."[dev]"

Then run the testing suite to confirm that everything is working properly:

pytest

Having trouble building the code? Open an issue and we'd be glad to help you troubleshoot.

Adding new training data

If usaddress is consistently failing on particular address patterns, you can adjust the parser's behavior by adding new training data to the model. Follow our guide in the training directory, and be sure to make a pull request so that we can incorporate your contribution into our next release!

Important links

Team

Bad Parses / Bugs

Report issues in the issue tracker

If an address was parsed incorrectly, please let us know! You can either open an issue or (if you're adventurous) add new training data to improve the parser's model. When possible, please send over a few real-world examples of similar address patterns, along with some info about the source of the data - this will help us train the parser and improve its performance.

If something in the library is not behaving intuitively, it is a bug, and should be reported.

Note on Patches/Pull Requests

  • Fork the project.
  • Make your feature addition or bug fix.
  • Send us a pull request. Bonus points for topic branches!

Copyright

Copyright (c) 2025 Atlanta Journal Constitution. Released under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

usaddress-0.5.13.tar.gz (912.5 kB view details)

Uploaded Source

Built Distribution

usaddress-0.5.13-py3-none-any.whl (67.7 kB view details)

Uploaded Python 3

File details

Details for the file usaddress-0.5.13.tar.gz.

File metadata

  • Download URL: usaddress-0.5.13.tar.gz
  • Upload date:
  • Size: 912.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for usaddress-0.5.13.tar.gz
Algorithm Hash digest
SHA256 5cebfb74c8e542c1ce4c0be9fe2843e62d03a31c029fafb5960590c556902876
MD5 d9a34035367f8661f7dfe48b68e9d309
BLAKE2b-256 8a17bb3ffdb3489dd517b7aba18a5196264c121b42385e2020fdec82925e62ec

See more details on using hashes here.

Provenance

The following attestation bundles were made for usaddress-0.5.13.tar.gz:

Publisher: python-publish.yml on datamade/usaddress

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file usaddress-0.5.13-py3-none-any.whl.

File metadata

  • Download URL: usaddress-0.5.13-py3-none-any.whl
  • Upload date:
  • Size: 67.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for usaddress-0.5.13-py3-none-any.whl
Algorithm Hash digest
SHA256 416910b5e80fda80d9c3b59e1b054a37f82edaca884d8d7260be684a15894d47
MD5 2aa9579cebf2a4ad6ce95f8a8d771249
BLAKE2b-256 1f9a19f51a4add58fdbaee22f04946dcce6b93873ededae026e578e665cb2a80

See more details on using hashes here.

Provenance

The following attestation bundles were made for usaddress-0.5.13-py3-none-any.whl:

Publisher: python-publish.yml on datamade/usaddress

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page