Zipcodes
Zipcodes is a simple library for querying U.S. zipcodes.
No system installation of sqlite3 is not required in order to use this package, which is ideal for cloud environments like AWS Lambda.
use zipcodes;
// >>> import zipcodes
// >>> assert zipcodes.is_real('77429')
// >>> assert len(zipcodes.similar_to('7742')) // != 0
// >>> exact_zip = zipcodes.matching('77429')[0]
// >>> filtered_zips = zipcodes.filter_by// (city="Cypress", state="TX")
// >>> assert exact_zip in filtered_zips
// >>> pprint.pprint(exact_zip)
// {'acceptable_cities': [],
// 'active': True,
// 'area_codes': ['281', '832'],
// 'city': 'Cypress',
// 'country': 'US',
// 'county': 'Harris County',
// 'lat': '29.9857',
// 'long': '-95.6548',
// 'state': 'TX',
// 'timezone': 'America/Chicago',
// 'unacceptable_cities': [],
// 'world_region': 'NA',
// 'zip_code': '77429',
// 'zip_code_type': 'STANDARD'}[
⚠️ The zipcode data was last updated on: Feb. 16, 2025 ⚠️
Installation
Zipcodes is available on crates.io:
$ cargo add zipcodes
or add the following to your Cargo.toml:
[]
= "0.3"
Zipcodes has no explicit MSRV.
Zipcode Data
The build script for the zipcode data outputs a JSON file containing all the zipcode data and zipped using bzip2. The data sources are stored under build/app/data.
Build the zipcode data for distribution:
$ build/app/__init__.py # outputs `zipcodes/zips.json.bz2`
Examples
TODO: Migrate from Python.
>>>
>>>
>>> # Simple zip-code matching.
>>>
>>> # Handles of Zip+4 zip-codes nicely. :)
>>>
>>> # Will try to handle invalid zip-codes gracefully...
>>>
>>> # Until it cannot.
>>>
:
...
: , and .
>>>
:
...
: , : or
>>>
:
...
: , .
>>> # Whether the zip-code exists within the database.
>>>
False
>>> # How handy!
>>>
True
>>> # Search for zipcodes that begin with a pattern.
>>>
>>> # Use filter_by to filter a list of zip-codes by specific attribute->value pairs.
>>>
>>> # Arbitrary nesting of similar_to and filter_by calls, allowing for great precision while filtering.
>>>
>>> # Have any other ideas? Make a pull request and start contributing today!
>>> # Made with love by Sean Pianka