A lightweight Python SDK for cascading Uganda address selection.
Supports:
District → County/Division → Sub-county → Parish → Village
The SDK is:
- dependency-free
- offline-first
- fast
- pure Python
- framework agnostic
Perfect for:
- Django apps
- Flask apps
- FastAPI
- CLI tools
- data processing
- backend validation
- Uganda-based SaaS products
pip install ug-addressfrom ug_address import UgAddress
addr = UgAddress()
districts = addr.get_districts()
print(districts[:5])[
{
"id": "98",
"name": "ABIM"
},
{
"id": "1",
"name": "ADJUMANI"
}
]from ug_address import UgAddress
addr = UgAddress()
# -----------------------------------
# Get districts
# -----------------------------------
districts = addr.get_districts()
print('DISTRICTS:\n')
for district in districts[:5]:
print(
district['id'],
'-',
district['name']
)
# -----------------------------------
# Select district
# -----------------------------------
addr.select_district('32') # Kampala
counties = addr.get_counties()
print('\nCOUNTIES:\n')
for county in counties:
print(
county['id'],
'-',
county['name']
)
# -----------------------------------
# Select county
# -----------------------------------
addr.select_county(counties[0]['id'])
subcounties = addr.get_subcounties()
print('\nSUBCOUNTIES:\n')
for subcounty in subcounties[:5]:
print(
subcounty['id'],
'-',
subcounty['name']
)
# -----------------------------------
# Select subcounty
# -----------------------------------
addr.select_subcounty(subcounties[0]['id'])
parishes = addr.get_parishes()
print('\nPARISHES:\n')
for parish in parishes[:5]:
print(
parish['id'],
'-',
parish['name']
)
# -----------------------------------
# Select parish
# -----------------------------------
addr.select_parish(parishes[0]['id'])
villages = addr.get_villages()
print('\nVILLAGES:\n')
for village in villages[:5]:
print(
village['id'],
'-',
village['name']
)
# -----------------------------------
# Select village
# -----------------------------------
addr.select_village(villages[0]['id'])
# -----------------------------------
# Final address
# -----------------------------------
print('\nFORMATTED ADDRESS:\n')
print(
addr.get_formatted_address()
)
# -----------------------------------
# Raw selection
# -----------------------------------
print('\nRAW SELECTION:\n')
print(
addr.get_selection()
)from ug_address import UgAddress
addr = UgAddress()All getters return alphabetically sorted lists.
Returns all Uganda districts.
districts = addr.get_districts()Returns counties/divisions for a district.
counties = addr.get_counties('32')If no ID is provided, the currently selected district is used.
Returns sub-counties for a county.
subcounties = addr.get_subcounties('69')Returns parishes for a sub-county.
parishes = addr.get_parishes('1546')Returns villages/cells for a parish.
villages = addr.get_villages('9127')Selecting a level automatically clears downstream selections.
addr.select_district('32')addr.select_county('69')addr.select_subcounty('1546')addr.select_parish('9127')addr.select_village('57217')The SDK supports reactive callbacks.
addr.on_district_change(
lambda e: print(e)
)Event structure:
{
"district_id": "32",
"counties": [...]
}addr.on_county_change(
lambda e: print(e)
)addr.on_subcounty_change(
lambda e: print(e)
)addr.on_parish_change(
lambda e: print(e)
)addr.on_village_change(
lambda e: print(e)
)Returns the currently selected hierarchy.
selection = addr.get_selection()Example:
{
"district": {
"id": "32",
"name": "KAMPALA"
},
"county": {
"id": "69",
"name": "KAMPALA CENTRAL DIVISION"
},
"subcounty": {
"id": "123",
"name": "CENTRAL WARD"
},
"parish": {
"id": "456",
"name": "NAKASERO PARISH"
},
"village": {
"id": "789",
"name": "NAKASERO VILLAGE A"
}
}Returns a human-readable address string.
addr.get_formatted_address()Example:
Nakasero Village A, Nakasero Parish, Central Ward, Kampala Central Division, KampalaClears all selected levels.
addr.reset()District
└── County / Division
└── Sub-county
└── Parish
└── Village / CellRelationships:
county.district === district.id
subcounty.county === county.id
parish.subcounty === subcounty.id
village.parish === parish.id- Uganda registration forms
- Backend address validation
- Location normalization
- GIS preprocessing
- CRM systems
- Fintech onboarding
- Delivery systems
- Government systems
- Health systems
- Logistics platforms
The SDK ships with embedded Uganda administrative data:
- no API requests
- no database needed
- works fully offline
MIT License
Free for:
- commercial use
- open-source projects
- SaaS products
- government systems
- educational projects