pypostalcode
pypostalcode is a fork of Nathan Van Gheem's excellent pyzipcode package. The zipcode database has been replaced with Canadian cities and their postal codes. The general usage is the same.
Canadian postal codes are six characters with this format: A1A 1A1, where A is a letter and 1 is a digit, with a space separating the third and fourth characters. The first three digits are the Forward Sortation Area (FSA), and the last three are the Local Delivery Unit (LDU). The FSA information is available from the report "Forward Sortation Area Boundary File, 2011 Census. Statistics Canada Catalogue no. 92-179-X" retrieved from
http://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/bound-limit-2011-eng.cfm
This module only uses the FSA designator for location. There are over 800,000 FSA+LDU combinations, but the 1,645 unique FSA values provide coarse resolution for most applications.
To install:
pip install pypostalcode
Basic usage:
>>> from pypostalcode import PostalCodeDatabase
>>> pcdb = PostalCodeDatabase()
>>> pc = 'V5K'
>>> location = pcdb[pc]
>>> location.postalcode
'V5K'
>>> location.city
'Vancouver (North Hastings- Sunrise)'
>>> location.province
'British Columbia'
>>> location.longitude
-123.0489
>>> location.latitude
49.293
>>> location.timezone
-8.0
>>> location.dst
1
Get a list of postal codes given a radius in kilometers:
>>> from pypostalcode import PostalCodeDatabase
>>> pcdb = PostalCodeDatabase()
>>> pc = 'T3Z'
>>> radius = 25
>>> results = pcdb.get_postalcodes_around_radius(pc, radius)
>>> for r in results:
... print(f'{r.postalcode}: {r.city}, {r.province}')
...
T3B: Calgary (Montgomery / Bowness / Silver Springs / Greenwood), Alberta
T3G: Calgary (Hawkwood / Arbour Lake / Royal Oak / Rocky Ridge), Alberta
T3H: Calgary (Discovery Ridge / Signal Hill / Aspen Woods / Patterson / Cougar Ridge), Alberta
T3L: Calgary (Tuscany / Scenic Acres), Alberta
T3R: Calgary Northwest, Alberta
T3Z: Redwood Meadows, Alberta
T4C: Cochrane, Alberta
© This data includes information copied with permission from Canada Post Corporation
This data includes data from GeoNames, which is distributed under a CC BY 4.0 license
Release files for pypostalcode 0.4.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pypostalcode-0.4.1.tar.gz | 106.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pypostalcode-0.4.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 212.3 kB
Release files / pypostalcode-0.4.1.tar.gz
| Download URL | pypostalcode-0.4.1.tar.gz |
|---|---|
| Size | 106.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5706b37c4bad5859723140ae1d9ef7be0dd094a3f68e27c64f8df20668e4b955
|
|
BLAKE2b-256 checksum How to use checksums |
ee669fb766b7d854d54e5f7e3aad729a6bcdd4762f3fab4623af9ed476fd3d14
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5
|
Release files / pypostalcode-0.4.1-py3-none-any.whl
| Download URL | pypostalcode-0.4.1-py3-none-any.whl |
|---|---|
| Size | 105.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
76c6ccff42b58604a485b568a34f296a15df05be3c6fc6ee7edc945bba45377b
|
|
BLAKE2b-256 checksum How to use checksums |
6f42830882f1dae63ee79e24b457064dd04ba13930138169017312af9da13506
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5
|