Package: django-postalcodes-mexico
Leave a star if you find this package useful.A Django Package for getting and handling the Mexican Postal Service (Correos de Mexico) postal codes information.Please leave a star if you find this package useful.CompatibilityPython (3.8 - 3.10)Django (2.2 - 4.1)DocumentationThe full documentation is athttps://django-postalcodes-mexico.readthedocs.io.QuickstartIf you want to use docker compose scroll down toquickstart using docker composeInstall django-postalcodes-mexico:pip install django-postalcodes-mexicoAdd it to yourINSTALLED_APPS:INSTALLED_APPS=(#...'django_postalcodes_mexico.apps.DjangoPostalcodesMexicoConfig',#...)Don’t forget to run migrate:pythonmanage.pymigrateIf the installation was succesful a new command namedimportpostalcodesmxwill be available.Basic Command usageIf you want to download all postal codes automatically run the following command:python manage.py importpostalcodesmxThis command will attempt to connect to theMexican 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 usageAlternatively, you can use the official xml file. Download it from theMexican Postal Service website. and unzip itPlace the xml file in the same level as your manage.py file and run the following command:python manage.py importpostalcodesmx --file=your_file_name.xmlif you don’t specify a file name the default file name fromMexican Postal Service website(Correos de Mexico) will be used:CPdescarga.xmlAdd API urlsAdd django-postalcodes-mexico’s URL patterns:fromdjango_postalcodes_mexicoimporturlsasdjango_postalcodes_mexico_urlsfromdjango.urlsimportpathurlpatterns=[# ...path('your-url',include(django_postalcodes_mexico_urls)),# ...]Quickstart using docker composeTo use docker compose to create an endpoint that returns the postal codes do the following:First, clone the project and enter the project directorygitclonehttps://github.com/EduardoZepeda/django-postalcodes-mexico.gitcddjango-postalcodes-mexico/Basic environmental variables need to be declared at the root of the project in a file nameddb.env# db.envPOSTGRES_PASSWORD=your-super-strong-passwordPOSTGRES_USER=yourUserPOSTGRES_DB=yourDatabaseNameSECRET_KEY=a-very-strong-django-secret-keyAlso a variable port, where the endpoint will be available, in your OS, must be placed inside a file named.env. I used 8009, but you can use any port you want.#.envPOSTAL_CODES_MX_PORT=8009Once the latest requirements are fulfilled you’re ready to go.docker-composeupThe script will fetch the most recent version of mexican postal codes directly to SEPOMEX (official correos de México website), create the required tables and get up a minimal django server, served using gunicorn.curl0.0.0.0:8009/29240/API UsageUse the following url to retrieve a postal codeyour-url/<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).FeaturesAutomatic postal codes table generationLocal file processingRunning TestsDoes the code actually work?source <YOURVIRTUALENV>/bin/activate
(myenv) $ pip install tox
(myenv) $ toxDevelopment commandspip install -r requirements_dev.txt
invoke -lCreditsTools used in rendering this package:Cookiecuttercookiecutter-djangopackageHistory0.1.0 (2021-01-15)First release on PyPI.0.2.0 (2021-01-16)Automatically postal codes download0.3.0 (2021-01-19)Local import functionality added0.3.1 (2021-01-19)Fix an error in README.rst syntax0.4.0 (2021-06-15)Add an extra search function0.5.0 (2021-11-05)Deprecate postal-code/ url0.6.0 (2022-10-06)Deprecate Python 3.6, Python 3.7. Add support for Django 4.1