All Projects → seanpianka → Zipcodes

seanpianka / Zipcodes

Licence: MIT license
A simple library for querying U.S. zipcodes.

Programming Languages

python
139335 projects - #7 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to Zipcodes

postal-codes-json-xml-csv
Collection of postal codes in different formats, ready for importing.
Stars: ✭ 181 (+187.3%)
Mutual labels:  zipcodes, zipcode, postal
Zip-code-of-all-countries-cities-in-the-world-CSV-TXT-SQL-DATABASE
Zip code of all countries in the world along with cities in CSV, TXT, SQL DATABASE
Stars: ✭ 35 (-44.44%)
Mutual labels:  zipcodes, zipcode
ViaCEP
The ViaCEP API/webservice .NET client
Stars: ✭ 21 (-66.67%)
Mutual labels:  zipcode, postal
InvestmentDataSampleApp
This app utilizes a SQLite databse, MVVM, along with these Xamarin.Forms controls: Search Bar, Picker, Grid, StackLayout, Navigation Page, ListView, ViewCell. It also shows how to tweak the UI to best appear on larger tablet screens.
Stars: ✭ 56 (-11.11%)
Mutual labels:  sqlite
SQLitePractice
数据库案例:1.使用时间和日期函数,增,查时间字段。2.利用ContentProvider,CursorLoader,SQLite实现数据库的观察者模式。3.RxJava,SQLBrite实现数据库的观察者模式。4.拷贝外部db文件到数据库中
Stars: ✭ 21 (-66.67%)
Mutual labels:  sqlite
ccxx
This is a cross-platform library software library about c, c ++, unix4, posix. Include gtest, benchmark, cmake, process lock, daemon, libuv, lua, cpython, re2, json, yaml, mysql, redis, opencv, qt, lz4, oci ... https://hub.docker.com/u/oudream
Stars: ✭ 31 (-50.79%)
Mutual labels:  sqlite
HighLite
An SQLite ORM for Android with automatic database migrations built with annotation processing
Stars: ✭ 77 (+22.22%)
Mutual labels:  sqlite
qtorm
Object-Relational Mapping Module for Qt
Stars: ✭ 16 (-74.6%)
Mutual labels:  sqlite
bookshelf-json-columns
Parse JSON columns with Bookshelf.js
Stars: ✭ 64 (+1.59%)
Mutual labels:  sqlite
sync-client
SyncProxy javascript client with support for all major embedded databases (IndexedDB, SQLite, WebSQL, LokiJS...)
Stars: ✭ 30 (-52.38%)
Mutual labels:  sqlite
database
Database Abstraction Layer, Schema Introspection, Schema Generation, Query Builders
Stars: ✭ 25 (-60.32%)
Mutual labels:  sqlite
SpeedTest-php
a speedtest php site
Stars: ✭ 28 (-55.56%)
Mutual labels:  sqlite
closql
Store EIEIO objects using EmacSQL
Stars: ✭ 23 (-63.49%)
Mutual labels:  sqlite
GitHubKotlinMPPSample
No description or website provided.
Stars: ✭ 15 (-76.19%)
Mutual labels:  sqlite
serverless data pipeline example
Build and Deploy A Serverless Data Pipeline on AWS
Stars: ✭ 24 (-61.9%)
Mutual labels:  aws-lambda
sack.vfs
Node addon which adds a virtual file system interface; websockets; json(6) parsing; sql support(sqlite,odbc); javascript sched_yield; ssl certificate generation; more...
Stars: ✭ 29 (-53.97%)
Mutual labels:  sqlite
acid-store
A library for secure, deduplicated, transactional, and verifiable data storage
Stars: ✭ 48 (-23.81%)
Mutual labels:  sqlite
microlight
A fully IndieWeb-compatible PHP blogging engine
Stars: ✭ 35 (-44.44%)
Mutual labels:  sqlite
Ionic-2-sqlite-demo
Simple demo to show how to work with Sqlite Storage in Ionic 2
Stars: ✭ 20 (-68.25%)
Mutual labels:  sqlite
database
Simple and easy go database micro framework
Stars: ✭ 12 (-80.95%)
Mutual labels:  sqlite

Zipcodes

Zipcodes is a simple library for querying U.S. zipcodes.

The Python sqlite3 module is not required in order to use this package.

>>> 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: Oct. 3, 2021 ⚠️

Downloads Supported Versions Contributors

Installation

Zipcodes is available on PyPI:

$ python -m pip install zipcodes

Zipcodes supports Python 2.6+ and Python 3.2+.

Compiling with PyInstaller

Add a data file to your PyInstaller bundle with the --add-data flag.

Linux and MacOS

--add-data "<path-to-package-install>/zipcodes/zips.json.bz2:zipcodes"

Windows

--add-data "<path-to-package-install>\zipcodes\zips.json.bz2;zipcodes"

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`

Tests

The tests are defined in a declarative, table-based format that generates test cases.

Run the tests directly:

$ python tests/__init__.py 

Examples

>>> from pprint import pprint
>>> import zipcodes

>>> # Simple zip-code matching.
>>> pprint(zipcodes.matching('77429'))
[{'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'}]


>>> # Handles of Zip+4 zip-codes nicely. :)
>>> pprint(zipcodes.matching('77429-1145'))
[{'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'}]

>>> # Will try to handle invalid zip-codes gracefully...
>>> print(zipcodes.matching('06463'))
[]

>>> # Until it cannot.
>>> zipcodes.matching('0646a')
Traceback (most recent call last):
  ...
ValueError: Invalid characters, zipcode may only contain digits and "-".

>>> zipcodes.matching('064690')
Traceback (most recent call last):
  ...
ValueError: Invalid format, zipcode must be of the format: "#####" or "#####-####"

>>> zipcodes.matching(None)
Traceback (most recent call last):
  ...
TypeError: Invalid type, zipcode must be a string.

>>> # Whether the zip-code exists within the database.
>>> print(zipcodes.is_real('06463'))
False

>>> # How handy!
>>> print(zipcodes.is_real('06469'))
True

>>> # Search for zipcodes that begin with a pattern.
>>> pprint(zipcodes.similar_to('1018'))
[{'acceptable_cities': [],
  'active': False,
  'area_codes': ['212'],
  'city': 'New York',
  'country': 'US',
  'county': 'New York County',
  'lat': '40.71',
  'long': '-74',
  'state': 'NY',
  'timezone': 'America/New_York',
  'unacceptable_cities': ['J C Penney'],
  'world_region': 'NA',
  'zip_code': '10184',
  'zip_code_type': 'UNIQUE'},
 {'acceptable_cities': [],
  'active': True,
  'area_codes': ['212'],
  'city': 'New York',
  'country': 'US',
  'county': 'New York County',
  'lat': '40.7143',
  'long': '-74.0067',
  'state': 'NY',
  'timezone': 'America/New_York',
  'unacceptable_cities': [],
  'world_region': 'NA',
  'zip_code': '10185',
  'zip_code_type': 'PO BOX'}]

>>> # Use filter_by to filter a list of zip-codes by specific attribute->value pairs.
>>> pprint(zipcodes.filter_by(city="Old Saybrook"))
[{'acceptable_cities': [],
  'active': True,
  'area_codes': ['860'],
  'city': 'Old Saybrook',
  'country': 'US',
  'county': 'Middlesex County',
  'lat': '41.3015',
  'long': '-72.3879',
  'state': 'CT',
  'timezone': 'America/New_York',
  'unacceptable_cities': ['Fenwick'],
  'world_region': 'NA',
  'zip_code': '06475',
  'zip_code_type': 'STANDARD'}]

>>> # Arbitrary nesting of similar_to and filter_by calls, allowing for great precision while filtering.
>>> pprint(zipcodes.similar_to('2', zips=zipcodes.filter_by(active=True, city='Windsor')))
[{'acceptable_cities': [],
  'active': True,
  'area_codes': ['757'],
  'city': 'Windsor',
  'country': 'US',
  'county': 'Isle of Wight County',
  'lat': '36.8628',
  'long': '-76.7143',
  'state': 'VA',
  'timezone': 'America/New_York',
  'unacceptable_cities': [],
  'world_region': 'NA',
  'zip_code': '23487',
  'zip_code_type': 'STANDARD'},
 {'acceptable_cities': ['Askewville'],
  'active': True,
  'area_codes': ['252'],
  'city': 'Windsor',
  'country': 'US',
  'county': 'Bertie County',
  'lat': '35.9942',
  'long': '-76.9422',
  'state': 'NC',
  'timezone': 'America/New_York',
  'unacceptable_cities': [],
  'world_region': 'NA',
  'zip_code': '27983',
  'zip_code_type': 'STANDARD'},
 {'acceptable_cities': [],
  'active': True,
  'area_codes': ['803'],
  'city': 'Windsor',
  'country': 'US',
  'county': 'Aiken County',
  'lat': '33.4730',
  'long': '-81.5132',
  'state': 'SC',
  'timezone': 'America/New_York',
  'unacceptable_cities': [],
  'world_region': 'NA',
  'zip_code': '29856',
  'zip_code_type': 'STANDARD'}]

>>> # Have any other ideas? Make a pull request and start contributing today!
>>> # Made with love by Sean Pianka
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].