US Zipcode Programmable Database

1.0.1 · active · verified Sun Apr 12

uszipcode is a Python library providing a programmable database for USA zip codes, including 2020 census data and geometry information. It offers a powerful and user-friendly search engine to query zip code data. The current version is 1.0.1, and the project maintains an active release cadence with regular updates.

Warnings

Install

Imports

Quickstart

Initialize the `SearchEngine` to interact with the US zip code database. The database will be downloaded automatically upon first use. You can then use methods like `by_zipcode` or `by_city_and_state` to retrieve detailed information.

from uszipcode import SearchEngine

# Initialize the search engine (downloads database on first run)
search = SearchEngine()

# Search by a specific zip code
zipcode = search.by_zipcode("10001")

if zipcode:
    print(f"Zip Code: {zipcode.zipcode}")
    print(f"City: {zipcode.major_city}")
    print(f"State: {zipcode.state}")
    print(f"Population: {zipcode.population}")
    print(f"Latitude: {zipcode.lat}, Longitude: {zipcode.lng}")
else:
    print("Zip code not found.")

# Example: Search by city and state
zipcodes_in_city = search.by_city_and_state(city="New York", state="NY")
print(f"\nFound {len(zipcodes_in_city)} zip codes in New York, NY.")
if zipcodes_in_city:
    print(f"First zip code: {zipcodes_in_city[0].zipcode}")

view raw JSON →