Skip to main content

A small package designed to help convert zip codes to OMB CBSA codes

Project description

USPS ZIP Code to OMB Core-Based Satistical Area (CBSA)

Background:

For those unfamiliar, the US Office of Management and Budget (OMB) defines Core Based Statistical Areas (CBSAs) for use by a multitude of other agencies, including the US Dept of Housing and Urban Development.

Meanwhile, most developers and users are not intimately acquainted with the CBSA codes, but may well be accustomed to USPS ZIP Codes. The OMB publishes "crosswalk files" periodically to help map ZIP codes to CBSAs, and this package serves as an easy means to utilize those without needing to call an API constantly.

This package just has one function, "convert", which takes in a 5-digit USPS ZIP Code and returns all of the info for matching rows in the OMB ZIP-CBSA Crosswalk File, namely CBSA code, USPS ZIP Pref City, USPS ZIP Pref State, and four different ratios of percentage of addresses in a ZIP code mapped to the given CBSA based on designation as residential, business, other, and total addresses.

The return value from this function is a list of dictionaries, each dictionary corresponding to a CBSA associated to the given ZIP code. If an invalid ZIP code is provided, or the ZIP doesn't map to any CBSA, the function instead returns "FALSE".

For more info on OMB CBSAs, and on how to use the output data, please visit the US HUD portal site: https://www.huduser.gov/portal/datasets/usps_crosswalk.html

Usage:

from zipToCBSA import convert
results = convert('54499')

for result in results:
    print(result)

results

{'zip': '54499', 'geoid': 43020, 'res_ratio': 0.817047817047817, 'bus_ratio': 0.9032258064516128, 'oth_ratio': 0.9428571428571428, 'tot_ratio': 0.8233766233766234, 'city': 'WITTENBERG', 'state': 'WI'}
{'zip': '54499', 'geoid': 48140, 'res_ratio': 0.167013167013167, 'bus_ratio': 0.0967741935483871, 'oth_ratio': 0.0571428571428571, 'tot_ratio': 0.1616883116883117, 'city': 'WITTENBERG', 'state': 'WI'}
{'zip': '54499', 'geoid': 44620, 'res_ratio': 0.0138600138600138, 'bus_ratio': 0.0, 'oth_ratio': 0.0, 'tot_ratio': 0.0129870129870129, 'city': 'WITTENBERG', 'state': 'WI'}
{'zip': '54499', 'geoid': 99999, 'res_ratio': 0.002079002079002, 'bus_ratio': 0.0, 'oth_ratio': 0.0, 'tot_ratio': 0.0019480519480519, 'city': 'WITTENBERG', 'state': 'WI'}

This code was inspired by the now-defunct zipcode2cbsa at https://github.com/macoj/zipcode2cbsa.

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

ziptocbsa-1.0.0.tar.gz (1.5 MB view details)

Uploaded Source

Built Distribution

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

ziptocbsa-1.0.0-py3-none-any.whl (742.4 kB view details)

Uploaded Python 3

File details

Details for the file ziptocbsa-1.0.0.tar.gz.

File metadata

  • Download URL: ziptocbsa-1.0.0.tar.gz
  • Upload date:
  • Size: 1.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for ziptocbsa-1.0.0.tar.gz
Algorithm Hash digest
SHA256 e34d21d937983692dd1a920b47f8d66c34e8ceff4c8c1a78b71c97a9d30128b5
MD5 34beb474753a6b07641131a07116bd7b
BLAKE2b-256 85254bec20753c331e8423ee5c9b268ad8eb74a10b517c749f40e7113ee342f6

See more details on using hashes here.

File details

Details for the file ziptocbsa-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: ziptocbsa-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 742.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for ziptocbsa-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 02730003b398bd1fe802153cbb9f044b774719cdc880c8a036c8794923a70586
MD5 97e63889af39cf1a9ec4b8931e5c744e
BLAKE2b-256 8c8a0dfbfc6ab35ac2a4ddc0a435b67aa51e655f673f80dacb5cee77055e4eff

See more details on using hashes here.

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