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.
pip install usVerified import paths — ran on the pinned version, not inferred.
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.
Upgrade your Python environment to 3.8 or newer. If unable to upgrade Python, pin 'us' to '<3.2.0' in your project's dependencies (e.g., `us<3.2.0`).
Ensure your project's `jellyfish` dependency is compatible with `jellyfish` 1.x. Review `jellyfish`'s changelog for any breaking changes if you directly use `jellyfish` functions.
Always check if the returned list from `match()` or similar functions is not empty before accessing elements (e.g., `if matched_states: state = matched_states[0]`).
When using `us.states.lookup()`, always perform a `None` check (e.g., `state = us.states.lookup('NotAState'); if state: print(state.name)`).Run `pip install us` to install the library, then ensure your import statement is `import us`.
Access the `lookup` method through the `states` attribute, for example: `us.states.lookup('Maryland')`.Access state objects by their attributes (e.g., `us.states.MD`) or use the `lookup` method (e.g., `us.states.lookup('Maryland')`).Always check if the result of `us.states.lookup()` is not `None` before attempting to access its attributes, for example: `state = us.states.lookup('Invalid'); if state: print(state.name)`.