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.3.0.tar.gz (16.6 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.3.0-py3-none-any.whl (18.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: kenyan_counties-0.3.0.tar.gz
  • Upload date:
  • Size: 16.6 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.3.0.tar.gz
Algorithm Hash digest
SHA256 face3c71c555564c83b0073f68c66e45e461187a22ad965a2ce5651ff5864218
MD5 903bab47199ba314ab4d9fec973f7a3f
BLAKE2b-256 893c1ec94a2d97abb5fb612e331ec6c80376b799b1c551a83e34e9cc1e1fc6d2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kenyan_counties-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 18.6 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.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bf12f4481dde555c813e9781a8245c8e086682612cd7486ec69eee25b92ec221
MD5 fe72275a433b01e4a93909be3a5aeb87
BLAKE2b-256 598180979cf852e4b0298252a264383f6647e5cc0ed7cdeddd2bf4a2a336ec5f

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