cepx-data
Offline Brazilian CEP database for cepx's local provider. It ships a prebuilt SQLite database derived from CEP Aberto, plus the pipeline that builds it.
Install it alongside cepx via the extra:
pip install "cepx[local]" # pulls in cepx-data
Then cepx resolves CEPs fully offline:
import cepx
cepx.cep("01001000", providers=["local"])
cepx-data exposes the database location for cepx to discover:
import cepx_data
cepx_data.db_path() # path to the bundled cepx.sqlite
cepx_data.has_db() # False in a source checkout, True once built/installed
Data model
CEP Aberto is point data (one row per CEP). Each CEP is one row in a ceps
table keyed on the CEP itself (cep INTEGER PRIMARY KEY, i.e. the rowid), and
the repeated UF / city / neighborhood / street values are deduplicated into
states / cities / neighborhoods / streets tables referenced by small
integer ids. A lookup is an exact match on the cep key joined to the four
dimension tables; a CEP absent from the dataset is a clean miss. Normalizing
the repeated text (rather than storing a UF|city|... string per row) keeps
the database ~42 MiB instead of ~82 MiB.
Coverage
Run python tools/coverage.py to report what the bundled database covers.
As of the current dataset:
1,137,150 CEPs
5,367 cities/localities
31,285 neighborhoods
611,241 streets
states ........... 27/27 (100%)
municipalities ... 5,367 present vs 5,570 IBGE
CEPs per macro-region (leading digit)
0xxxxxxx SP (Grande São Paulo) 114,641 ##################
1xxxxxxx SP (interior/litoral) 186,209 ##############################
2xxxxxxx RJ, ES 131,820 #####################
3xxxxxxx MG 116,180 ###################
4xxxxxxx BA, SE 64,380 ##########
5xxxxxxx PE, AL, PB, RN 91,280 ###############
6xxxxxxx CE, PI, MA, PA, AM, AC, AP, RR 112,120 ##################
7xxxxxxx DF, GO, TO, MT, MS, RO 156,020 #########################
8xxxxxxx PR, SC 106,105 #################
9xxxxxxx RS 58,395 #########
(CEP Aberto counts districts finer than IBGE municipalities, so the municipality figure is a loose lower bound.)
Building the database
The database is a build artifact, produced during the release pipeline. No CEP Aberto data is committed to this repo. To build locally you only need a logged-in CEP Aberto session:
export CEPABERTO_COOKIE='_cepaberto_session=...; remember_user_token=...'
export CEPABERTO_TOKEN='...' # from a browser download request
make data # fetch dumps + refs, then build
tools/fetch_cepaberto.py: parallel authenticated download of the per-state dumps AND thecities.csv/states.csvreference tables (each response is a ZIP wrapping a CSV; auto-extracted), with retries, intodumps/.tools/load_cepaberto.py: joins the dumps against the reference tables and writessrc/cepx_data/data/cepx.sqlite.tools/build_cep_db.py: the SQLite writer (deduped dimension tables +cepskeyed on the CEP).tools/coverage.py: reports what the built database covers.
The full dataset is ~1.14M CEPs (~42 MiB).
Releases
On merge to main, release-please opens/tags releases. The publish job runs
make data (using the repo secrets CEPABERTO_COOKIE / CEPABERTO_TOKEN),
builds the wheel, and publishes to PyPI via Trusted Publishing.
License & attribution
Code is MIT. The bundled database (and the reference tables it is built from) are derived from CEP Aberto and licensed under the Open Database License (ODbL) 1.0 — attribution and share-alike required. No CEP Aberto data is kept in this repository; it is fetched at build time. See NOTICE.
Development
make setup
make check # unit tests + coverage + pre-commit
Metadata
Release files for cepx-data 0.1.2
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 |
|---|---|---|---|---|
| cepx_data-0.1.2.tar.gz | 17.9 MB | Without provenance | Details for cepx_data-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cepx_data-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for cepx_data-0.1.2-py3-none-any.whl |
Total release size: 35.8 MB
Release files / cepx_data-0.1.2.tar.gz
| Download URL | cepx_data-0.1.2.tar.gz |
|---|---|
| Size | 17.9 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6271cc693fa35552c3c95ae52b74b612795ac4a33eabe8c9b323115be2f3c61e
|
|
BLAKE2b-256 checksum How to use checksums |
bb7ffc47f37944cce06a3e0c9cb67c34ea14d41b65941cde3bbe04ba368cc146
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.27 {"installer":{"name":"uv","version":"0.11.27","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / cepx_data-0.1.2-py3-none-any.whl
| Download URL | cepx_data-0.1.2-py3-none-any.whl |
|---|---|
| Size | 17.9 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e133de20591b05562fc71cdc9974bebcce6db3028d3dfb129363e99dcfe15efc
|
|
BLAKE2b-256 checksum How to use checksums |
996fd107a54d6ebe990f52904de64c40827b23e96d53f7ca0d9d8d21c17b4cfa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.27 {"installer":{"name":"uv","version":"0.11.27","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for cepx-data 0.1.2
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.