Skip to main content

A lightweight, performant, and scalable Python package for Kenyan counties, constituencies, and wards, optimized for FastAPI and Django.

Project description

Kenyan Counties

A lightweight, performant Python package providing data for all 47 counties, constituencies, and wards in Kenya. Optimized for speed with zero I/O overhead at runtime.

Installation

# Core only
pip install kenyan-counties

# With FastAPI / Pydantic support
pip install kenyan-counties[fastapi]

# With Django support
pip install kenyan-counties[django]

# Everything
pip install kenyan-counties[all]

Usage

Core API

from kenyan_counties import (
    get_all_counties,
    get_county_by_code,
    get_county_by_name,
    get_constituencies_for_county,
    get_wards_for_constituency,
)

# All 47 counties
counties = get_all_counties()

# Lookup by code (1-47)
mombasa = get_county_by_code(1)
print(mombasa)  # <County: Mombasa (1)>

# Lookup by name (case-insensitive)
nairobi = get_county_by_name("nairobi")
print(nairobi.code)  # 47

# Constituencies in a county
constituencies = get_constituencies_for_county(1)

# Wards in a constituency
wards = get_wards_for_constituency(1, "Changamwe")
print(wards[0].name)  # Port Reitz

FastAPI

from fastapi import FastAPI
from kenyan_counties.fastapi import router

app = FastAPI()
app.include_router(router)

This adds the following endpoints:

Method Path Description
GET /counties/ List all 47 counties
GET /counties/{code} Get a county by code
GET /counties/{code}/constituencies List constituencies for a county

Django

Add to INSTALLED_APPS:

INSTALLED_APPS = [
    ...
    "kenyan_counties",
]

Run migrations and seed the database:

python manage.py migrate
python manage.py load_kenya_counties

This creates County, Constituency, and Ward records you can query via the Django ORM.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kenyan_counties-0.1.0.tar.gz (16.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kenyan_counties-0.1.0-py3-none-any.whl (17.3 kB view details)

Uploaded Python 3

File details

Details for the file kenyan_counties-0.1.0.tar.gz.

File metadata

  • Download URL: kenyan_counties-0.1.0.tar.gz
  • Upload date:
  • Size: 16.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.13.5 Darwin/25.2.0

File hashes

Hashes for kenyan_counties-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0b988fb7093102ba5827361934e76623716a33ddb4da1cfa193761312d60257c
MD5 80498acca0f2a29c1cabf51494d8d75f
BLAKE2b-256 a91377739680b5e51bbfd4a2cffe32262a631a47531a6a4ae7d41574336d66ee

See more details on using hashes here.

File details

Details for the file kenyan_counties-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: kenyan_counties-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 17.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.13.5 Darwin/25.2.0

File hashes

Hashes for kenyan_counties-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 825c86e649371ece8c64115075aab78c2e84bfca7de27417ffc3aeb7b75b3e0e
MD5 a042f900a71261d353eb031377cfd229
BLAKE2b-256 772a2f0ba279b80465ef74fcd6986237c5000f65c7838042193a7e4c1136cc4e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page