This repository demonstrates a production-grade implementation of an IP-2-Country service exercise. The service provides IP geolocation functionality with built-in rate limiting and extensible database support.
The service was built according to the following requirements:
- Clear and readable code implementation
- Configurable service architecture
- REST API endpoint at
/v1/find-country?ip=2.22.233.255
returning location data in JSON format:{ "country": "XXXX", "city": "XXXX" }
- JSON error responses with appropriate HTTP status codes:
{ "error": "XXX" }
- Extensible design supporting multiple IP-2-Country databases (currently implements CSV) but easily extensible to other database types
- Custom rate-limiting mechanism with configurable requests per second
- Production-grade implementation with proper testing, configuration, and deployment setup
- FastAPI-based REST API
- Custom rate limiting implementation using Redis
- Configurable through YAML and environment variables
- Extensible IP database support (currently CSV-based)
- Docker and Docker Compose support
- Test suite
- Development and production configurations
- Python 3.9+
- Docker and Docker Compose
- Conda
-
Clone the repository:
git clone <repository-url> cd ip-to-country-service
-
Run with Docker Compose:
docker-compose up --build
-
For development:
One-time setup:
# Create and activate conda environment conda create -n ip2country_env python=3.9 conda activate ip2country_env # Install requirements pip install -r requirements.txt
Each time you develop:
# Start Redis for development docker-compose -f docker-compose.dev.yml up -d # Run the development server ./scripts/run_dev.sh
-
Run tests:
./scripts/run_tests.sh
Get country and city information for an IP address.
Parameters:
ip
(string, required): The IP address to look up
Success Response (200):