A comprehensive FastAPI-based REST API for Ghana's administrative divisions including regions, districts, and towns.
- 16 Regions: All current regions of Ghana with their capitals
- Districts: Administrative districts within each region
- Towns: Major towns and cities with population data
- Search Functionality: Search across regions, districts, and towns
- Population Queries: Filter towns by population ranges
- Modular Architecture: Clean, maintainable code structure
GET /api/v1/regions- Get all regionsGET /api/v1/regions/{id}- Get region by IDGET /api/v1/regions/{id}/details- Get region with districtsGET /api/v1/regions/name/{name}- Get region by nameGET /api/v1/regions/search?q={query}- Search regions
GET /api/v1/districts- Get all districtsGET /api/v1/districts/{id}- Get district by IDGET /api/v1/districts/{id}/details- Get district with townsGET /api/v1/regions/{region_id}/districts- Get districts by regionGET /api/v1/districts/search?q={query}- Search districts
GET /api/v1/towns- Get all townsGET /api/v1/towns/{id}- Get town by IDGET /api/v1/districts/{district_id}/towns- Get towns by districtGET /api/v1/towns/search?q={query}- Search townsGET /api/v1/towns/largest?limit={n}- Get largest townsGET /api/v1/towns/population?min_pop={min}&max_pop={max}- Filter by population
- Clone the repository:
git clone <repository-url>
cd GhanaRegionsAPI- Create a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies:
pip install -r requirements.txt- Run the application:
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000Once running, visit:
- API Documentation: http://localhost:8000/docs
- Alternative Docs: http://localhost:8000/redoc
- Health Check: http://localhost:8000/health
app/
├── main.py # FastAPI application entry point
├── models/ # Pydantic data models
│ ├── region.py
│ ├── district.py
│ └── town.py
├── routers/ # API route handlers
│ ├── regions.py
│ ├── districts.py
│ └── towns.py
├── services/ # Business logic layer
│ ├── region_service.py
│ ├── district_service.py
│ └── town_service.py
└── database/ # Data storage
└── data.py # Sample data
{
"id": 7,
"name": "GREATER ACCRA",
"capital": "ACCRA",
"districts": [
{
"id": 1,
"name": "Accra Metropolitan",
"region_id": 7
}
]
}{
"id": 1,
"name": "Accra Metropolitan",
"region_id": 7,
"towns": [
{
"id": 1,
"name": "Accra",
"district_id": 1,
"population": 2291352
}
]
}- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.