████████████████████████████████████████ 100%
A lightweight FastAPI service for looking up Tanzanian regions, cities, and districts from a 6-digit pincode.
The API is designed for applications such as e-commerce checkout forms, where a customer enters a pincode and the corresponding location information can be automatically populated.
- 🔎 Look up a location using a 6-digit pincode
- 📦 Perform bulk pincode lookups
- 🇹🇿 Tanzania-focused location data
- ✅ Automatic pincode validation using Pydantic
- ⚡ Fast API powered by FastAPI
- 🛡️ Custom error handling for invalid and unknown pincodes
- 📚 Interactive API documentation through FastAPI
- 🧩 Easy to integrate with checkout and address forms
- Python
- FastAPI
- Pydantic
- Uvicorn
🇹🇿 EMTAA — Tanzania Pincode Lookup API
│
├── 📁 Scripts/
│ └── ⚙️ Supporting / utility scripts
│
├── 📄 main.py
│ └── 🚀 FastAPI application entry point
│ ├── API routes
│ ├── Pincode lookup
│ ├── Bulk lookup
│ └── Request / response handling
│
├── 📄 models.py
│ └── 🧩 Pydantic data models
│ ├── Request schemas
│ ├── Response schemas
│ └── Data validation
│
├── 📄 data.py
│ └── 🇹🇿 Tanzania pincode/location dataset
│ ├── Regions
│ ├── Cities
│ └── Districts
│
├── 📄 exceptions.py
│ └── ⚠️ Custom API exceptions
│ ├── Invalid pincode
│ ├── Pincode not found
│ └── Validation errors
│
├── 📄 requirements.txt
│ └── 📦 Python dependencies
│ ├── FastAPI
│ ├── Pydantic
│ └── Uvicorn
│
├── 📄 README.md
│ └── 📚 Project documentation
│ ├── Features
│ ├── Installation
│ ├── API usage
│ └── Examples
│
├── 📄 .gitignore
│ └── 🚫 Ignored files / directories
│
└── 📄 pyvenv.cfg
└── 🐍 Python virtual-environment configuration
┌─────────────────────────┐
│ Client / App │
│ E-commerce / Checkout │
└────────────┬────────────┘
│
│ 6-digit Pincode
▼
┌─────────────────────────┐
│ main.py │
│ FastAPI API Layer │
└────────────┬────────────┘
│
┌──────────────┼──────────────┐
▼ ▼ ▼
┌────────────┐ ┌────────────┐ ┌──────────────┐
│ models.py │ │ data.py │ │ exceptions.py│
│ Validation │ │ 🇹🇿 Data │ │ Error │
│ & Schemas │ │ Lookup │ │ Handling │
└────────────┘ └─────┬──────┘ └──────────────┘
│
▼
┌────────────────────┐
│ Tanzania Location │
│ Data │
├────────────────────┤
│ Region │
│ City │
│ District │
└─────────┬──────────┘
│
▼
┌─────────────────────────┐
│ API Response │
│ │
│ Pincode → Region │
│ → City │
│ → District │
└─────────────────────────┘
emtaa/
│
├── main.py # FastAPI application and API routes
├── models.py # Pydantic request/response models
├── data.py # Pincode and location data
├── exceptions.py # Custom exceptions and handlers
├── requirements.txt # Python dependencies
├── Scripts/ # Virtual environment scripts
├── .gitignore
└── README.md
git clone https://github.com/Ibrahist/emtaa.git
cd emtaapython -m venv emtaaActivate it:
emtaa\Scripts\activatepython3 -m venv emtaa
source emtaa/bin/activatepip install -r requirements.txtuvicorn main:app --reloadThe API will normally be available at:
http://127.0.0.1:8000
Once the server is running, FastAPI automatically provides interactive documentation.
http://127.0.0.1:8000/docs
http://127.0.0.1:8000/redoc
Returns a welcome message.
GET /{
"message": "Welcome to the Pincode lookup API!"
}Look up a location using a 6-digit pincode.
GET /pincode/123456{
"pincode": "123456",
"region": "Dar es Salaam",
"city": "Dar es Salaam",
"district": "Ilala"
}Pincodes must:
- Contain exactly 6 digits
- Exist in the available pincode dataset
Invalid or unknown pincodes return an appropriate error response.
Look up multiple pincodes in a single request.
{
"pincodes": ["123456", "654321", "111111"]
}{
"status": "success",
"found": 3,
"not_found": 0,
"results": [
{
"pincode": "123456",
"region": "Dar es Salaam",
"city": "Dar es Salaam",
"district": "Ilala"
}
],
"missing": []
}The bulk endpoint accepts up to 10 pincodes per request.
The project currently includes sample pincode mappings for locations including:
| Pincode | Region | City | District |
|---|---|---|---|
123456 |
Dar es Salaam | Dar es Salaam | Ilala |
654321 |
Mwanza | Mwanza | Mwanza |
111111 |
Arusha | Arusha | Arusha |
222222 |
Dodoma | Dodoma | Dodoma |
333333 |
Mbeya | Mbeya | Mbeya |
444444 |
Kilimanjaro | Moshi | Moshi |
555555 |
Tanga | Tanga | Tanga |
666666 |
Zanzibar | Zanzibar City | Zanzibar |
Note: These are currently sample/test records. For production use, the dataset should be replaced or expanded with verified Tanzanian postal-code data.
The API can be integrated into an e-commerce checkout flow:
Customer enters pincode
↓
Frontend sends pincode to API
↓
GET /pincode/{code}
↓
API returns region, city & district
↓
Checkout form automatically fills location
This can reduce manual address entry and improve the checkout experience.
curl http://127.0.0.1:8000/pincode/123456curl -X POST http://127.0.0.1:8000/pincodes \
-H "Content-Type: application/json" \
-d "{\"pincodes\":[\"123456\",\"654321\",\"111111\"]}"Before using the API in production, consider:
- Replacing sample pincode data with verified postal data
- Adding API authentication if required
- Adding rate limiting
- Adding logging and monitoring
- Deploying behind HTTPS
- Adding automated tests
- Moving location data from an in-memory dictionary to a database for larger datasets
- Adding CORS configuration for frontend applications
- Adding proper deployment configuration
The project is considered 100% complete in its current scope. Future releases may introduce additional capabilities such as:
- Add complete Tanzanian postal-code dataset
- Add database support
- Add automated tests
- Add CORS configuration
- Add API authentication
- Add rate limiting
- Add Docker support
- Add deployment configuration
- Add API versioning
- Add search by region, city, or district
- Add frontend checkout demo
Contributions are welcome.
- Fork the repository
- Create a feature branch
git checkout -b feature/my-feature- Make your changes
- Commit your changes
git add .
git commit -m "Add my feature"- Push your branch
git push origin feature/my-feature- Open a Pull Request
This project is currently available without a specified license.
If you intend to distribute or accept external contributions, consider adding an appropriate open-source license.
Ibrahist
GitHub: https://github.com/Ibrahist
If you find this project useful, consider giving the repository a ⭐ on GitHub.
The data provided are auto-generated for testing purposes only. I accept no responsibility for the authenticity or accuracy of the provided data.