A quick and dirty script/api for syncing postal codes / zip codes with a local sqlite3 database.
### Why?
Personally I dislike hitting up a remote server for mostly static information.
Since GeoNames provides this data under a Creative Commons license, this script
pulls all countries and drops it in a sqlite3 for (relatively) fast lookup.
## Important!
This data is provided by GeoNames under the Creative Commons license (http://creativecommons.org/licenses/by/3.0/).
If you use this data, you must provide credit to them whenever it is used.
The python-geonameszip library itself is under the MIT license.
### Example:
Main uses are for postal code validation:
```python
import geonameszip
# NOTE: country is required due to duplicate zip codes based on country.
us_result = geonameszip.lookup_postal_code('77098', 'US')
print(us_result)
# {'city': u'Houston', 'country': u'US', 'lon': -95.4118, 'county': u'Harris', 'state': u'Texas', 'postal_code': u'77098', 'lat': 29.735, 'state_abbreviation': u'TX'}
mx_result = geonameszip.lookup_postal_code('77098', 'MX')
print(mx_result)
# {'city': u'Barrio Bravo', 'country': u'MX', 'lon': -88.6458, 'county': u'Othon P Blanco', 'state': u'Quintana Roo', 'postal_code': u'77098', 'lat': 19.4083, 'state_abbreviation': u'ROO'}
```
## API
`geonameszip`
```python
import_from_file(source_path)
```
- Drops the postal_codes table in the sqlite3 database
- Re-creates the tabl.e
- Inserts all the data provided by a file formatted like `allCountries.txt`.
```python
lookup_postal_code(postal_code, country, conn=None, cursor=None)
```
- Selects the first available option for the `postal_code`, `country` combination.
- NOTE: Currently, if multiple entries match, only the top-most is provided.
```python
update_postal_code(postal_code, country, city, state, state_abbreviation, county, lat, lon, conn=None,commit=True, cursor=None)
```
- _Inserts_ the values provided in the arguments into the database.
- NOTE: This always _inserts_ the data, never updates. The data isn't consistently unique and the database has no primary key so it isn't easy to provide a way to update a single row.
- This can create duplicate entries.
For python-geonameszip (this python code ONLY -- not the data):
The MIT License
===============
Copyright (c) 2009 Anton Grigoryev
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
# GEONAMES Data:
Creative Commons Deed
=====================
_Licensees may copy, distribute, display and perform the work and make derivative works based on it only if they give the author or licensor the credits in the manner specified by [http://creativecommons.org/licenses/by/3.0/](http://creativecommons.org/licenses/by/3.0/)._
## Summary
_This is a human-readable summary of (and not a substitute for) the [license](http://creativecommons.org/licenses/by/3.0/)._
### You are free to:
- *Share* — copy and redistribute the material in any medium or format
- *Adapt* — remix, transform, and build upon the material
- for any purpose, even commercially.
- The licensor cannot revoke these freedoms as long as you follow the license terms.
### Under the following terms:
- *Attribution* — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
- *No additional restrictions* — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits.
### Notices:
You do not have to comply with the license for elements of the material in the public domain or where your use is permitted by an applicable exception or limitation.
No warranties are given. The license may not give you all of the permissions necessary for your intended use. For example, other rights such as publicity, privacy, or moral rights may limit how you use the material.
Metadata
Release files for geonameszip 0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| geonameszip-0.1.4.tar.gz | 7.7 kB | Without provenance | Details for geonameszip-0.1.4.tar.gz |
Release files / geonameszip-0.1.4.tar.gz
| Download URL | geonameszip-0.1.4.tar.gz |
|---|---|
| Size | 7.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
af7ca0b23e1ff65e6c46aac381f911c7e2be55f6abf81d888a4b8d38b79aea5c
|
|
BLAKE2b-256 checksum How to use checksums |
cf06667ac47a7138fc128447c0f50b268168b0232e8b47365abb620d6a12916c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for geonameszip 0.1.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.