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.2.0.tar.gz (16.3 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.2.0-py3-none-any.whl (17.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: kenyan_counties-0.2.0.tar.gz
  • Upload date:
  • Size: 16.3 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.2.0.tar.gz
Algorithm Hash digest
SHA256 10ba0676cd50d9ca1f3f4d6f908fa4b59cf24fa664717a5485396fb75aed06e7
MD5 cb2fede191b9b0a17f94c4ad948cf4a7
BLAKE2b-256 ab3999db8b0d3a05e673ac959c8cfbb248866b33d74d95786d7a5629979350c2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kenyan_counties-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 17.7 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1f9d839555802d4d8383b4a76ca1fb22a4167008bbdc035246b3dc94b12893c3
MD5 069b570a3c4e235d42864b54bf828b8a
BLAKE2b-256 839fc77d3d602c539924408d91986247aef68faa3b0363e7c969886d42bd7d7a

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