A lightweight REST API that predicts the gender of a given name using the Genderize.io API. Built with FastAPI and deployed on Railway.
Author: Anidu Yakubu Khalid
Internship: HNG Backend Stage 0
https://genderizeapi-production-bde5.up.railway.app/api/classify?name={name}
- Python 3.13
- FastAPI — web framework
- Uvicorn — ASGI server
- HTTPX — async HTTP client for calling Genderize.io
- Railway — deployment platform
backend/
├── app.py # Main application
├── Procfile # Railway process configuration
└── requirements.txt # Python dependencies
- Python 3.10+
- pip
-
Clone the repository
git clone https://github.com/your-username/your-repo-name.git cd your-repo-name/backend -
Create and activate a virtual environment
python -m venv .venv # Windows .venv\Scripts\activate # macOS/Linux source .venv/bin/activate
-
Install dependencies
pip install -r requirements.txt
-
Run the server locally
uvicorn app:app --reload
The API will be available at
http://localhost:8000.
Classifies the gender of a given name.
| Parameter | Type | Required | Description |
|---|---|---|---|
name |
string | Yes | The name to classify |
curl "http://localhost:8000/api/classify?name=khalid"{
"success": 200,
"data": {
"name": "khalid",
"gender": "male",
"probability": 0.98,
"is_confident": true,
"sample_size": 3456,
"processed_at": "2025-01-01T12:00:00.000000"
}
}| Field | Type | Description |
|---|---|---|
name |
string | The name that was classified |
gender |
string | "male" or "female" |
probability |
float | Confidence score between 0 and 1 |
is_confident |
boolean | true if probability is 0.7 or above |
sample_size |
integer | Number of records used for the prediction |
processed_at |
string | UTC timestamp of when the request was processed |
All errors follow this structure:
{
"status": "error",
"message": "<error message>"
}| Status Code | Cause |
|---|---|
400 |
Bad request sent to Genderize API |
422 |
Missing or invalid name parameter, or no prediction available for the name |
429 |
Rate limit exceeded (max 1 request per 500ms per IP) |
500 |
Internal server error |
502 |
Genderize API is unreachable or timed out |
If Genderize returns no result for a name (e.g. very rare or ambiguous names):
{
"status": "error",
"message": "No prediction available for the provided name"
}The API enforces a 500ms cooldown per IP address to prevent abuse. Exceeding this limit returns a 429 response.
The API allows cross-origin requests from all origins via:
Access-Control-Allow-Origin: *
This project is deployed on Railway using the following Procfile:
web: uvicorn app:app --host 0.0.0.0 --port $PORT
- Push your code to GitHub
- Create a new project on Railway
- Connect your GitHub repository
- Set the Root Directory to
backend(if applicable) - Railway auto-detects the
Procfileand deploys
fastapi
uvicorn
httpx
starlette
This project is open source and available under the MIT License.