PHPackages                             anglemx/mexico-postal-codes - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. anglemx/mexico-postal-codes

ActiveGit[Utility &amp; Helpers](/categories/utility)

anglemx/mexico-postal-codes
===========================

PHP utility and database to lookup Mexico Postal Code information

v1.0.1(4y ago)012.4k↓14.7%MITPHPPHP &gt;=7.2

Since Jan 8Pushed 4y ago2 watchersCompare

[ Source](https://github.com/Angle/mexico-postal-codes)[ Packagist](https://packagist.org/packages/anglemx/mexico-postal-codes)[ Docs](https://github.com/Angle/mexico-postal-codes)[ RSS](/packages/anglemx-mexico-postal-codes/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (1)Versions (3)Used By (0)

Angle Mexico Postal Codes
=========================

[](#angle-mexico-postal-codes)

PHP utility and database to lookup Mexico Postal Code information

How to Use
----------

[](#how-to-use)

```
$postalCode = PostalCode::fastLookup('64630');

printf('Postal Code:    %s' . PHP_EOL, $postalCode->getPostalCode());
printf('State:          %d %s %s' . PHP_EOL, $postalCode->getState(), $postalCode->getStateIso(), $postalCode->getStateName());

printf('Settlements:' . PHP_EOL);

foreach ($postalCode->getSettlements() as $settlement) {
    printf('> %s %s' . PHP_EOL, $settlement->getId(), $settlement->getName());
    printf('  Type:   %s - %s' . PHP_EOL, $settlement->getType(), $settlement->getTypeName());
    printf('  City:   %s' . PHP_EOL, $settlement->getCity());
    printf('  County: %s' . PHP_EOL, $settlement->getCounty());
    printf('  Zone:   %s - %s' . PHP_EOL, $settlement->getZone(), $settlement->getZoneName());
}
```

```
Postal Code:    64630
State:          19 NLE Nuevo León
Settlements:
> 330 Colinas de San Jerónimo
  Type:   9 - Colonia
  City:   Monterrey
  County: Monterrey
  Zone:   U - Urbano
> 331 San Jemo
  Type:   9 - Colonia
  City:   Monterrey
  County: Monterrey
  Zone:   U - Urbano

```

Database Source
---------------

[](#database-source)

The database is downloaded from the official *Correos de México* website at: [https://www.correosdemexico.gob.mx/SSLServicios/ConsultaCP/CodigoPostal\_Exportar.aspx](https://www.correosdemexico.gob.mx/SSLServicios/ConsultaCP/CodigoPostal_Exportar.aspx) and it is then parsed and processed to optimize the filesize a bit.

*Last database update: January 2, 2022*

The database is published by SEPOMEX (SErvicio POstal MEXicano) and includes a Disclaimer Notice that allows personal use of the data but no commercial use at all. This must be honored by anybody using this PHP library:

> El Catálogo Nacional de Códigos Postales, es elaborado por Correos de México y se proporciona en forma gratuita para uso particular, no estando permitida su comercialización, total o parcial, ni su distribución a terceros bajo ningún concepto.

Database Processing
-------------------

[](#database-processing)

To update and autogenerate, place the `CPdescarga.txt` file inside the `resources/` directory, then execute the `ProcessSepomexPostalCodeDatabase.php` script.

- CPdescargatxt.zip -&gt; 2MB compressed file
- CPdescarga.txt -&gt; 14.6MB pipe-separated file
- mx-postal-codes.csv -&gt; 6.94MB nested pipe-separated file

The column definitions can be found in this link:

Database Analytics
------------------

[](#database-analytics)

We've included a very basic and barebones analytics script in `AnalyticsSepomexPostalCodeDatabase.php` that parses the raw database and generates a few insights into the data.

Interesting facts from the Jan 2nd, 2022 database:

- There are 31,827 unique PostalCodes in Mexico
- PostalCode 85203 in Cajeme, Sonora, has 310 settlements registered in the same PostalCode.

Testing
-------

[](#testing)

```
php vendor/bin/phpunit tests/PostalCodeLookupTest.php
```

TO-DO
-----

[](#to-do)

- Implement "database expand" for PostalCodes to minimize the library install size. The current PostalCode database file weights 6.94MB, if we zip it we could reduce it to 1.6MB.
- The "SingleLookup" method for PostalCodes scans the file very quickly before parsing. This could be further optimized if the database file was ordered by "popularity", or at least by "cities first, rural second".

References
----------

[](#references)

Some interesting tidbits from

1. Los dos primeros dígitos identifican una entidad federativa y en el caso de la Ciudad de México una alcaldía.
2. El tercer dígito identifica en las entidades federativas un conjunto de municipios, un municipio o parte de un municipio y en la Ciudad de México parte de una alcaldía
3. El cuarto dígito identifica en las entidades federativas y en la Ciudad de México un conjunto de asentamientos humanos urbanos y rurales.
4. El quinto dígito identifica en las entidades federativas y en la Ciudad de México un conjunto de asentamientos humanos urbanos y rurales o un asentamiento humano urbano rural o una oficina postal.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~100 days

Total

2

Last Release

1490d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/936483?v=4)[Edmundo Fuentes](/maintainers/edmundofuentes)[@edmundofuentes](https://github.com/edmundofuentes)

---

Top Contributors

[![edmundofuentes](https://avatars.githubusercontent.com/u/936483?v=4)](https://github.com/edmundofuentes "edmundofuentes (4 commits)")

---

Tags

zipcodepostalcodemexicoangle

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/anglemx-mexico-postal-codes/health.svg)

```
[![Health](https://phpackages.com/badges/anglemx-mexico-postal-codes/health.svg)](https://phpackages.com/packages/anglemx-mexico-postal-codes)
```

###  Alternatives

[eclipxe/cfdiutils

PHP Common utilities for Mexican CFDI 3.2, 3.3 &amp; 4.0

141129.9k6](/packages/eclipxe-cfdiutils)[phpcfdi/cfdi-sat-scraper

Web Scraping para extraer facturas electrónicas desde la página del SAT

9018.0k](/packages/phpcfdi-cfdi-sat-scraper)[flyingluscas/viacep-php

ViaCEP PHP SDK

3640.2k](/packages/flyingluscas-viacep-php)[phpcfdi/rfc

PHP library to deal with Mexican RFC

2562.4k3](/packages/phpcfdi-rfc)[phpcfdi/cfdi-cleaner

Clean up Mexican CFDI

1334.1k1](/packages/phpcfdi-cfdi-cleaner)[magedev/brazilzipcode

Magento 2 module to use brazil zipcode search services.

1119.1k1](/packages/magedev-brazilzipcode)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
