US State Meta Information

3.2.0 · active · verified Fri Apr 10

The 'us' library provides an easy way to work with US state and territory meta information, offering data such as names, abbreviations, FIPS codes, and contiguous status. It also includes functions for looking up states by various criteria. The current version is 3.2.0, and it generally follows an active release cadence, with updates for Python version compatibility and dependency upgrades.

Warnings

Install

Imports

Quickstart

The quickstart demonstrates how to import the `us` library and access state and territory objects. It shows direct access by abbreviation, lookup by name, fuzzy matching, and accessing lists of all entities. It also includes accessing the `unitedstatesofamerica` object and its new `birthday` attribute.

import us

# Access state objects directly
california = us.states.CA
print(f"California FIPS: {california.fips}")

# Look up states by name, abbreviation, or FIPS code
new_york = us.states.lookup('New York')
print(f"New York abbr: {new_york.abbr}")

# Fuzzy matching (requires 'jellyfish' library)
matched_states = us.states.match('Kanzus')
if matched_states:
    print(f"Did you mean: {matched_states.name} ({matched_states.abbr})?")

# Access a list of all states and territories
print(f"Total states and territories: {len(us.states.all) + len(us.territories.all)}")

# Access special objects like 'unitedstatesofamerica'
usa = us.unitedstatesofamerica
print(f"USA name: {usa.name}, Birthday: {usa.birthday}")

view raw JSON →