A Django Package for handling Mexico postal codes
Project description
A Django Package for getting and handling the Mexican Postal Service (Correos de Mexico) postal codes information.
Documentation
The full documentation is at https://django-postalcodes-mexico.readthedocs.io.
Quickstart
Install django-postalcodes-mexico:
pip install django-postalcodes-mexico
Add it to your INSTALLED_APPS:
INSTALLED_APPS = (
...
'django_postalcodes_mexico.apps.DjangoPostalcodesMexicoConfig',
...
)
Don’t forget to run migrate:
python manage.py migrate
If the installation was succesful a new command named importpostalcodes will be available.
Basic Command usage
If you want to download all postal codes automatically run the following command:
python manage.py importpostalcodes
This command will attempt to connect to the Mexican Postal Service website (Correos de Mexico) and download the public zip file that contains all the postal codes available in xml format, extract them, process them and create the corresponding table in your database.
Local import usage
Alternatively, you can use the official xml file. Download it from the Mexican Postal Service website. and unzip it
Place the xml file in the same level as your manage.py file and run the following command:
python manage.py importpostalcodes --file=your_file_name.xml
if you don’t specify a file name the default file name from Mexican Postal Service website (Correos de Mexico) will be used:
CPdescarga.xml
Add API urls
Add django-postalcodes-mexico’s URL patterns:
from django_postalcodes_mexico import urls as django_postalcodes_mexico_urls
from django.urls import path
urlpatterns = [
...
path('', include(django_postalcodes_mexico_urls)),
...
]
API Usage
Use the following url to retrieve a postal code
postal-code/<slug:postal_code>/
# examples:
# postal-code/01000/
# postal-code/02000/
If the request was successful you will receive a response in JSON formatted in this way:
{
"municipio": "San Cristóbal de las Casas",
"estado": "Chiapas",
"colonias": [
"La Isla",
"La Merced",
"De Mexicanos",
"San Ramón",
"1ro de Mayo"
],
"codigoPostal": "29240"
}
Please note that a Postal Code is associated with only one state(estado) and state area (municipio) but with many city areas (colonias).
Features
Automatic postal codes table generation
Local file processing
Running Tests
Does the code actually work?
source <YOURVIRTUALENV>/bin/activate (myenv) $ pip install tox (myenv) $ tox
Development commands
pip install -r requirements_dev.txt invoke -l
Credits
Tools used in rendering this package:
History
0.1.0 (2021-01-15)
First release on PyPI.
0.2.0 (2021-01-16)
Automatically postal codes download
0.3.0 (2021-01-19)
Local import functionality added
0.3.1 (2021-01-19)
Fix an error in README.rst syntax
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
Built Distribution
Hashes for django-postalcodes-mexico-0.4.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8488ebf06ad58e61a1bcf1b1b99ba281883c77526aa2e1b280970f68d16a0d66 |
|
MD5 | 816faeb1fc2db223615106c7b24a4075 |
|
BLAKE2b-256 | 9b6bdabc24bfd39d5c5eecfe2e448e47244d0fa6b2712ef822c9bfb0a53084cf |
Hashes for django_postalcodes_mexico-0.4.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c58325d5f4ec878c9968c40d3eccbed1c83acf8c87d17754f449bb840e2d1c73 |
|
MD5 | 124aa757d79d05c82f40e2569fed4b63 |
|
BLAKE2b-256 | 4c79f5043854839515d81b5c0603a822b0ffc47ce1788a440048a24b0e08da73 |