tanzania-postcodes
Real Tanzania postal codes, sourced directly from TCRA's official gazetted National Postcode System (Government Gazette Notice No. 240, 22 April 2016) — not a third-party site's compiled or scraped version.
No Python package for Tanzania postcodes existed before this one.
pgeocode, the most common
general-purpose postal code library, explicitly doesn't support Tanzania
(ValueError: country=TZ is not a known country code) — its data comes
from GeoNames, which has no real Tanzania coverage.
Install
pip install tanzania-postcodes
Usage
import tanzania_postcodes as tzpc
# Look up everything at a postcode
tzpc.lookup("16112")
# [Postcode(region='Dar Es Salaam', district='UBUNGO', ward='Goba',
# postcode='16112', locality='Goba', ...), ...]
# Search by name (ward, district, region, or locality)
tzpc.search("Goba")[0].postcode
# '16112'
# List all 26 regions
tzpc.regions()
# List all wards, optionally scoped to one region
tzpc.wards("Dar Es Salaam")
Each result is a Postcode:
Postcode(
region: str, # e.g. "Dar Es Salaam"
district: str | None, # e.g. "UBUNGO"
ward: str, # e.g. "Goba" -- the unit TCRA's postcode identifies
postcode: str, # e.g. "16112"
locality: str | None, # mtaa/village within the ward
sub_locality: str | None, # kitongoji, where the source PDF has one
old_postcode: str | None, # legacy code, where the source PDF has one
district_postcode: str | None,
)
Coverage
All 26 regions, 67,000+ locality-level records, 3,900+ unique
ward postcodes. A postcode identifies a ward — the same postcode
applies to every village/mtaa within it, which is why lookup() usually
returns multiple records for one code.
Where this data comes from, and how it was built
TCRA publishes the postcode list as 26 separate regional PDFs (no
CSV/Excel version exists) at
tcra.go.tz/services/publication-of-postcode-list.
Each PDF's table uses merged cells for repeated values, and — found
during development — three different column layouts across the 26
files (some have a separate District level, some don't; some have an Old
Postcode column, some don't; one region's table has no header row at
all). scripts/parse_pdfs.py detects each table's actual header and
maps columns by name rather than assuming one fixed schema, with a
documented fallback for the one region missing a header entirely.
scripts/download_pdfs.py and scripts/parse_pdfs.py are included in
this repo if you want to verify the extraction yourself or regenerate
the dataset from TCRA's source PDFs directly.
Why this exists
Built after actually needing a Tanzania postcode (Goba ward, Dar es
Salaam — 16112), confirming no Python package or well-covered general
library had it, and finding TCRA's own official data was real, current,
and genuinely extractable — just never turned into a package before.
License
MIT for this package's code. The underlying postcode data is Tanzania government public record (Government Gazette Notice No. 240, 2016).
Metadata
Release files for tanzania-postcodes 0.1.0
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 | |
|---|---|---|---|---|
| tanzania_postcodes-0.1.0.tar.gz | 553.7 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| tanzania_postcodes-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 1.1 MB
Release files / tanzania_postcodes-0.1.0.tar.gz
| Download URL | tanzania_postcodes-0.1.0.tar.gz |
|---|---|
| Size | 553.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
689ff4d18097fa02de05efedf6dd7c290f894fba6b8025ee104349a4122c3d20
|
|
BLAKE2b-256 checksum How to use checksums |
32eb19c4979069a09d4483ef5901106e049df519ff5ee7dbd520bf35ef267fe3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.12
|
Release files / tanzania_postcodes-0.1.0-py3-none-any.whl
| Download URL | tanzania_postcodes-0.1.0-py3-none-any.whl |
|---|---|
| Size | 587.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d2ab719e7ccf0700325aac84052cfb6208b93765cd7d92cdc1c3de49bc511578
|
|
BLAKE2b-256 checksum How to use checksums |
3414a479ea8186a412afb5e9c7397f024bba97e933fad5b66da895051584be59
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.12
|
Security for tanzania-postcodes 0.1.0
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.