Afrogeo
Offline-first African location verification for Python.
Validate country and administrative divisions without an internet connection. Each country defines its own level names (e.g. State/LGA for Nigeria, Province/Municipality for South Africa).
Installation
pip install afrogeo
Usage
Afrogeo provides a simple verify function that takes a dictionary and returns a Result object.
Basic Example (Nigeria)
from afrogeo import verify
# Lowercase input is fine — output is always canonical casing from the data
data = {
"country": "nigeria",
"state": "lagos",
"lga": "agege"
}
result = verify(data)
if result.valid:
print(f"Validated: {result.normalized['state']} - {result.normalized['lga']}")
else:
print(f"Errors: {result.errors}")
Full Validation (including settlement)
data = {
"country": "NG", # Supports codes or full names
"state": "LA", # Supports division codes
"lga": "Agege",
"city": "Agege" # Optional settlement
}
result = verify(data)
Normalize helper
normalize() runs the same validation as verify() and returns the canonical dict (or {} on failure):
from afrogeo import normalize
data = normalize({"country": "NG", "state": "LA", "lga": "Agege"})
# data["division_1_name"] -> "Lagos"
# data["division_2_name"] -> "Agege"
# data["state"] / data["lga"] -> same values (legacy keys)
Generic aliases
You can use country-agnostic keys instead of state / lga / city:
result = verify({
"country": "NG",
"division_1": "Lagos",
"division_2": "Agege",
"settlement": "Agege"
})
Primary keys take precedence when both primary and alias are provided.
Features
- Offline-First: Uses local JSON data for instant verification.
- Multi-Country Schema: One file per country with flexible admin level labels.
- Data Normalization: Converts codes to full names and standardizes output.
- Case Insensitive: All inputs (
country,state,lga,cityand aliases) are matched without regard to case."lagos","LAGOS", and"Lagos"all validate; normalized output uses canonical casing from the dataset (e.g."Lagos", not"lagos"). - Dynamic Loading & Cache Safety: Loads only the data for the country you are verifying, caching reads safely without risk of dataset mutation.
- Type Annotated: Fully typed with PEP 561 (
py.typed) support formypyandpyright.
API Reference
verify(user_input: dict) -> Result
The user_input dictionary accepts:
country(Required): Full name or ISO code.state(Required): Level-1 division name or code. Alias:division_1.lga(Required): Level-2 division name. Alias:division_2.city(Optional): Settlement name. Alias:settlement.
For all countries, state, lga, and city are generic slots (e.g. province, municipality, settlement for South Africa). Check level_1_label and level_2_label in the normalized output for the country's terminology.
Returns a Result object:
result.valid(orbool(result)):Trueif valid,Falseotherwise.result.errors: List of error message strings (empty if valid).result.normalized: Canonical dict with:- Legacy:
country_code,country,state_code,state,lga,city,capital - Generic:
division_1_code,division_1_name,division_2_name,settlement,settlements - Labels:
levels,level_1_label,level_2_label,country_name
- Legacy:
- Dictionary Convenience Methods:
result["state"]— Indexing shorthand forresult.normalized["state"]result.get("state", default)— Safe lookup with default"state" in result— Membership checkresult.to_dict()— Returns a copy of the normalized dictionary
normalize(user_input: dict) -> dict
Returns result.normalized on success, or {} if validation fails.
Result
Importable directly from afrogeo for type checking and custom handling:
from afrogeo import Result, verify
Contributing
Data is stored in afrogeo/data/. See CONTRIBUTING.md for the JSON schema and how to add a country.
Metadata
Release files for afrogeo 0.2.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 | Actions |
|---|---|---|---|---|
| afrogeo-0.2.0.tar.gz | 19.3 kB | With provenance | Details for afrogeo-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| afrogeo-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for afrogeo-0.2.0-py3-none-any.whl |
Total release size: 34.6 kB
Release files / afrogeo-0.2.0.tar.gz
| Download URL | afrogeo-0.2.0.tar.gz |
|---|---|
| Size | 19.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
43fd0747437db5fa3f6b24384f3caba39c0bba8bc0293fcfef8dbf7b39c73672
|
|
BLAKE2b-256 checksum How to use checksums |
620e570c22b4553311156e5f69ec34386424a48909f187070c9f6cd59413eee2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 1, 2026.
Transparency logRelease files / afrogeo-0.2.0-py3-none-any.whl
| Download URL | afrogeo-0.2.0-py3-none-any.whl |
|---|---|
| Size | 15.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9a0569afb6711ec88a34e604dc81a108af41638d50290102dfdcfa5f01609408
|
|
BLAKE2b-256 checksum How to use checksums |
82ba4195dd8d400254aea190652300e7221620bb40274c23a8af80e153a21c32
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 1, 2026.
Transparency logSecurity for afrogeo 0.2.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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for afrogeo-0.2.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 1, 2026.
Transparency logA 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.