Skip to main content

Extended fork of random-address with broader coverage and batch sampling

Project description

Random Address

This is a tool to retrieve a real address from a list of real of random addresses that geocode successfully (tested on Google's Geocoding API service). The address data comes from open address datasets including OpenAddresses and Overture Maps. The addresses are deliberately not linked to people or businesses; the only guarantee is that they are real addresses from open address datasets.

The original addresses were pulled from OpenAddress where the "Required attribute" field was present and not "Yes". Newer records are imported only when they include address line 1, city, state, ZIP code, and coordinates. See "Attribution" below for a list of sources (also included in each data file).

This project was inspired by Real, Random Address Data (RRAD) project.

About This Extended Fork

This fork extends the original neosergio/random-address library while keeping the same Python import path:

import random_address

Key additions in this fork:

  • PyPI distribution name: random-address-extended
  • Coverage expanded from the original packaged dataset's 3,270 records across 17 state/DC codes to 1,031,008 complete geocoded records across all 50 states plus DC.
  • ZIP coverage expanded to 26,506 ZIP codes, including 23,326 ZIP codes with at least 35 records, 23,683 ZIP codes with at least 25 records, and 24,724 ZIP codes with at least 5 records.
  • Added precomputed ZIP cluster metadata for 23,340 compact latitude/longitude groups.
  • Packaged data is stored in SQLite so imports do not need to inflate and parse a 1M-record JSON document before the first lookup.
  • Added real_random_addresses(...) for batch sampling with optional state, city, ZIP, seed, uniqueness, and fallback behavior.
  • Added reproducible ingestion workflows for OpenAddresses samples, Overture Maps address samples, NH GRANIT New Hampshire data, and local Netsyms-style SQLite address data.

Additional data sources used by this fork:

See DATASET_COVERAGE.md for the current state-by-state counts and DATA_INGESTION.md for the data refresh workflow.

Travis (.com) PyPI PyPI - License PyPI - Downloads PyPI - Python Version PyPI - Status

Installation

Run the following to install:

$ pip install random-address

This extended fork can be installed from PyPI as:

$ pip install random-address-extended

The Python import remains:

import random_address

Usage

from random_address import real_random_address

# Generate a dictionary with valid random address information
real_random_address()

There are other 3 functions that can be used:

>>> import random_address
>>> random_address.real_random_address_by_state('CA')
{'address1': '37600 Sycamore Street', 'address2': '', 'city': 'Newark', 'state': 'CA', 'postalCode': '94560', 'coordinates': {'lat': 37.5261943, 'lng': -122.0304698}}
>>> random_address.real_random_address_by_postal_code('32409')
{'address1': '711 Tashanna Lane', 'address2': '', 'city': 'Southport', 'state': 'FL', 'postalCode': '32409', 'coordinates': {'lat': 30.41437699999999, 'lng': -85.676568}}
>>> random_address.real_random_address_by_city('Newark')
{'address1': '37600 Sycamore Street', 'address2': '', 'city': 'Newark', 'state': 'CA', 'postalCode': '94560', 'coordinates': {'lat': 37.5261943, 'lng': -122.0304698}}

Batch sampling is also available:

>>> random_address.real_random_addresses(count=3, state='NH', seed=123)
[{'address1': '9 DUCK POND CIRCLE', ...}, ...]

>>> random_address.real_random_addresses(
...     count=100,
...     state='KY',
...     postal_code='40214',
...     city='Louisville',
... )

When both postal_code and city are provided, the batch helper first uses strict matches. If there are not enough strict matches, the default fallback='city_or_postal_code' fills the remaining batch from the same city or same ZIP code while keeping state as a hard filter when provided. Use fallback='none', fallback='postal_code', or fallback='city' to change that behavior.

Clustered sampling can return a geographically compact group from one ZIP code:

>>> random_address.real_random_address_cluster(
...     count=25,
...     postal_code='06040',
...     seed=123,
... )
[{'address1': '310 Timrod Road', ...}, ...]

Clustered sampling only uses ZIP groups with at least count records and at least min_postal_code_count records. The default min_postal_code_count=6 keeps ZIPs with 1-5 records out of clustered results. When enough records are available, the helper uses packaged build-time cluster metadata so runtime sampling stays fast and avoids proximity calculations on the full dataset.

These functions allow you to inspect the dataset contents:

>>> random_address.list_available_states()
['AK', 'AL', 'AR', 'AZ', 'CA', 'CO', 'CT', 'DC', 'DE', 'FL', ...]

>>> random_address.list_available_postal_codes()
['32409', '93546', '94560', '99577', ...]

>>> random_address.list_available_cities()
['Mammoth Lakes', 'Newark', 'Panama City Beach', 'Southport', ...]

>>> random_address.list_states_with_counts()
{'CA': 1234, 'FL': 900, 'VA': 200, ...}

>>> random_address.list_postal_codes_with_counts()
{'32409': 10, '99577': 15, ...}

>>> random_address.list_cities_with_counts()
{'Panama City Beach': 6, 'Newark': 12, ...}

>>> random_address.get_summary()
{
    'total_addresses': 1031008,
    'unique_states': 51,
    'unique_cities': 18377,
    'unique_postal_codes': 26506
}

Expected value example:

{'address1': '210 Beachcomber Drive', 'address2': '', 'city': 'Pismo Beach', 'state': 'CA', 'postalCode': '93449', 'coordinates': {'lat': 35.169193, 'lng': -120.694434}}

Functions Overview

  • real_random_address(): Retrieve a random valid US address.
  • real_random_address_by_state(state: str): Retrieve a random address filtered by US state code.
  • real_random_address_by_postal_code(postal_code: str): Retrieve a random address filtered by US postal code.
  • real_random_address_by_city(city: str): Retrieve a random address filtered by US city.
  • real_random_addresses(...): Retrieve a batch of random addresses with optional state, city, ZIP, seed, uniqueness, and fallback behavior.
  • real_random_address_cluster(...): Retrieve a geographically compact batch from one ZIP code with optional state, city, ZIP, seed, minimum ZIP depth, and maximum radius filters.

Attribution

Data is collected from the OpenAddresses project, Overture Maps, and NH GRANIT. The repository also includes an optional local importer for the Netsyms Address Database, but Netsyms source files are not committed to this package. The full generated attribution list is included in random_address/addresses-us-all.sqlite. Original sources include:

  • City of Haddam (CT)
  • Ciy of Hartford (CT)
  • City of Lyme (CT)
  • City of Manchester (CT)
  • City of Watertown (CT)
  • City of Avon (CT)
  • Town of Fairfield (CT)
  • City of Groton (CT)
  • Office of Geographic Information (MassGIS), Commonwealth of Massachusetts, MassIT (MA)
  • VT Enhanced 911 Board, VCGI (VT)
  • City of Huntsville (AL)
  • City of Montgomery (AL)
  • Shelby County (AL)
  • Talladega County (AL)
  • City of Fayetteville (AR)
  • Arkansas Geographic Information Office (AR)
  • City of Washington (DC)
  • Bay County (FL)
  • Brevard County (FL)
  • Charlotte County (FL)
  • Citrus County (FL)
  • Clay County (FL)
  • Highlands County, FL (FL)
  • Hillsborough County (FL)
  • City of Savannah (GA)
  • Gordon County (GA)
  • Muscogee County (GA)
  • Sumter County (GA)
  • Metro Louisville, LOJIC partners (KY)
  • Anne Arundel County (MD)
  • City of Baltimore (MD)
  • Frederick County (MD)
  • Oklahoma and Logan Counties - Association of Central Oklahoma Governments (OK)
  • Kern, Cleveland, Canadian, Logan Counties (OK)
  • City of Nashville (TN)
  • Cooke,Fannin,Grayson Counties - Texoma Council of Governments (TX)
  • Municipality of Anchorage (AK)
  • Copyright © 2015 Kenai Peninsula Borough (AK)
  • Matanuska-Susitna Borough (AK)
  • City of Glendale (AZ)
  • City of Mesa (AZ)
  • Alameda County (CA)
  • Amador County (CA)
  • City of Berkeley (CA)
  • Butte County (CA)
  • City of Bakersfield (CA)
  • City of Carson (CA)
  • City of Cupertino (CA)
  • City of Hayward and Fairview. Licensed for Public Use (CA)
  • City of Mountain View (CA)
  • City of Orange (CA)
  • Contra Costa County (CA)
  • El Dorando County (CA)
  • Fresno County (CA)
  • Humboldt County (CA)
  • Kern County (CA)
  • Kings County (CA)
  • Lake County (CA)
  • Lassen County (CA)
  • Los Angeles County (CA)
  • Madera County (CA)
  • Marin County (CA)
  • Merced County (CA)
  • Mono County (CA)
  • Monterey County (CA)
  • Napa County (CA)
  • County of Nevada, California (CA)
  • Orange County (CA)
  • City of Palo Alto (CA)
  • County of Placer (CA)
  • Secramento County (CA)
  • San Bernardino County (CA)
  • San Diego Geographic Information Source - JPA (CA)
  • San Joaquin County (CA)
  • San Luis Obispo County (CA)
  • San Mateo County (CA)
  • Santa Barbara County (CA)
  • Santa Clara County (CA)
  • Santa Cruz County (CA)
  • Shasta County (CA)
  • Solano County (CA)
  • Sonoma County (CA)
  • Stanislaus County (CA)
  • Tuolumne County (CA)
  • Yolo County (CA)
  • Yuba County (CA)
  • Arapahoe County (CO)
  • Archuleta County (CO)
  • City of Arvada (CO)
  • City of Aurora (CO)
  • City of Boulder (CO)
  • City of Fort Collins (CO)
  • City of Greeley (CO)
  • City of Loveland (CO)
  • City of Westminster (CO)
  • Gilpin County (CO)
  • Gunnison County (CO)
  • Jefferson County (CO)
  • Larimer County (CO)
  • Mesa County (CO)
  • Pitkin County (CO)
  • Pubelo County (CO)
  • San Miguel County (CO)
  • City of Honolulu (HI)
  • Arlington County (VA)

Requesting New Location Data

If you need deeper coverage for a specific city, state, or postal code, please open a new GitHub Issue describing your request.

The dataset now includes all 50 US states plus DC and more than 26,000 ZIP codes. Incomplete records are not added.

Requests will be evaluated and added gradually, in order to:

  • Keep the library size small and lightweight.
  • Ensure quality and functionality remain stable across versions.

We appreciate your suggestions and contributions!

Contributing

Contributions are welcome! Feel free to submit pull requests, report issues, or suggest improvements.

Developing Random Address

To install random-address, along the tools you need to develop and run tests, run the following in your virtualenv:

$ pip install -e .[dev]

Run the normal test suite:

$ python -m pytest

Runtime performance checks are opt-in so they do not slow normal CI:

$ RUN_PERFORMANCE_TESTS=1 python -m pytest tests/test_performance.py

To refresh Overture data for clustered 25-35 address ZIP groups:

$ python -m pip install duckdb
$ python data/import_overture_samples.py --per-postal-code 35 --sample-mode clustered --build-clusters

To rebuild cluster metadata from an existing dataset without fetching new data:

$ python data/build_address_clusters.py --cluster-size 35

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

random_address_extended-1.3.2.tar.gz (30.3 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

random_address_extended-1.3.2-py3-none-any.whl (30.4 MB view details)

Uploaded Python 3

File details

Details for the file random_address_extended-1.3.2.tar.gz.

File metadata

  • Download URL: random_address_extended-1.3.2.tar.gz
  • Upload date:
  • Size: 30.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for random_address_extended-1.3.2.tar.gz
Algorithm Hash digest
SHA256 3306cfe8faeeb2d750bc3233edc8fdf24e1cafca980a9778a8187190d6859fb1
MD5 b89527be0241c238f84f110508e58277
BLAKE2b-256 751cf8baa4a1bcf08e3eed91298d96f5e12b4726627c42be3a363d9b58a19c7a

See more details on using hashes here.

Provenance

The following attestation bundles were made for random_address_extended-1.3.2.tar.gz:

Publisher: publish.yml on alexagius/random-address

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

File details

Details for the file random_address_extended-1.3.2-py3-none-any.whl.

File metadata

File hashes

Hashes for random_address_extended-1.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 25167096fb146b1ff1c804c2b5c2f19ae7c86ceda1ba6cb6069aa03e3ff1ff44
MD5 f1919727cb961e615405f78b2ba03b06
BLAKE2b-256 363185822403da9e9d3bd2d47ddfb2b6b000701056ac93d52793e59eb28cd594

See more details on using hashes here.

Provenance

The following attestation bundles were made for random_address_extended-1.3.2-py3-none-any.whl:

Publisher: publish.yml on alexagius/random-address

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

Supported by

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