Offline Brazilian CEP database for cepx's local provider, built from CEP Aberto (ODbL).
Project description
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
Project details
Release history Release notifications | RSS feed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cepx_data-0.1.2.tar.gz.
File metadata
- Download URL: cepx_data-0.1.2.tar.gz
- Upload date:
- Size: 17.9 MB
- Tags: Source
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6271cc693fa35552c3c95ae52b74b612795ac4a33eabe8c9b323115be2f3c61e
|
|
| MD5 |
58400caa7ef80c3004d35ebe6a54fe05
|
|
| BLAKE2b-256 |
bb7ffc47f37944cce06a3e0c9cb67c34ea14d41b65941cde3bbe04ba368cc146
|
File details
Details for the file cepx_data-0.1.2-py3-none-any.whl.
File metadata
- Download URL: cepx_data-0.1.2-py3-none-any.whl
- Upload date:
- Size: 17.9 MB
- Tags: Python 3
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e133de20591b05562fc71cdc9974bebcce6db3028d3dfb129363e99dcfe15efc
|
|
| MD5 |
07ff09051eb6d54a635d397750637f9d
|
|
| BLAKE2b-256 |
996fd107a54d6ebe990f52904de64c40827b23e96d53f7ca0d9d8d21c17b4cfa
|