A lightweight FastAPI service that provides IP geolocation data using MaxMind's GeoLite2 databases.
- π IP Geolocation Lookup - Detailed location data for any IP address
- π Daily Auto Updates - GeoIP databases refreshed daily via GitHub Actions
- π³ Docker Ready - Pre-built images on GitHub Container Registry
- π Fast API - Built with FastAPI for high performance
- π Bulk Lookup - Query multiple IPs in a single request
- π Auto Documentation - Swagger UI and ReDoc included
- π Type Safe - Full Pydantic validation
Pull and run the pre-built image from GitHub Container Registry:
docker pull ghcr.io/ntthanh2603/geoip-server:latest
docker run -p 4360:4360 ghcr.io/ntthanh2603/geoip-server:latestAccess the API at: http://localhost:4360
git clone https://github.com/ntthanh2603/geoip-server.git
cd geoip-server
cp .env.example .env
# Edit .env with your MaxMind credentials
docker-compose up -d| Endpoint | Method | Description | Example |
|---|---|---|---|
/ |
GET | Get client's IP address | curl http://localhost:4360/ |
/{ip} |
GET | Lookup single IP | curl http://localhost:4360/8.8.8.8 |
/bulk/{ips} |
GET | Lookup multiple IPs | curl http://localhost:4360/bulk/8.8.8.8,1.1.1.1 |
/docs |
GET | Swagger UI documentation | Open in browser |
/redoc |
GET | ReDoc documentation | Open in browser |
{
"query": "8.8.8.8",
"status": "success",
"continent": "North America",
"continentCode": "NA",
"country": "United States",
"countryCode": "US",
"region": "CA",
"regionName": "California",
"city": "Mountain View",
"district": "",
"zip": "94035",
"lat": 37.386,
"lon": -122.0838,
"timezone": "America/Los_Angeles",
"offset": 5,
"currency": "USD",
"isp": "Google LLC",
"org": "Google LLC",
"as": "AS15169 Google LLC",
"asname": "Google LLC"
}Get a MaxMind license key (free):
- Sign up: https://www.maxmind.com/en/geolite2/signup
- Generate license key: https://www.maxmind.com/en/accounts/current/license-key
# Build and run
docker-compose up --build
# Run in background
docker-compose up -d
# View logs
docker-compose logs -f
# Stop
docker-compose downPre-built Docker images with daily updated GeoIP databases are available at: ghcr.io/ntthanh2603/geoip-server
| Tag | Description | Update Frequency |
|---|---|---|
latest |
Latest stable build | On every push to main |
YYMMDD |
Daily snapshot | Daily at 00:00 UTC |
main-<sha> |
Specific commit | On demand |
# Latest version
docker pull ghcr.io/ntthanh2603/geoip-server:latest
# Specific date (e.g., Nov 2, 2025)
docker pull ghcr.io/ntthanh2603/geoip-server:251102| Workflow | Schedule | Purpose |
|---|---|---|
| Daily Docker Build | Daily at 00:00 UTC | Update GeoIP databases & build images |
To enable automated builds:
- Navigate to: Settings β Secrets and variables β Actions
- Add repository secrets:
Name: GEOIPUPDATE_ACCOUNT_ID
Value: <your_maxmind_account_id>
Name: GEOIPUPDATE_LICENSE_KEY
Value: <your_maxmind_license_key>
- Go to Actions tab β Select workflow β Run workflow
The workflow will:
- β Verify secrets
- β Download latest GeoIP databases
- β Build Docker image
- β Push to GitHub Container Registry
geoip-server/
βββ .github/workflows/ # CI/CD workflows
β βββ docker-build.yml # Daily build automation
βββ src/
β βββ app.py # FastAPI application
β βββ configs/
β β βββ path_database.py # Database path config
β βββ controlers/
β β βββ geoip_controler.py # API endpoints
β βββ services/
β β βββ geoip_service.py # GeoIP lookup logic
β βββ types/
β βββ ip_geolocaltion.py # Pydantic models
βββ main.py # Entry point
βββ Dockerfile # Docker configuration
βββ docker-compose.yml # Compose configuration
βββ requirements.txt # Python dependencies
βββ .env.example # Environment template
| Technology | Purpose |
|---|---|
| FastAPI | Modern Python web framework |
| MaxMind GeoLite2 | IP geolocation databases |
| Pydantic | Data validation |
| Docker | Containerization |
| GitHub Actions | CI/CD automation |
This project uses GeoLite2 data created by MaxMind, available from MaxMind.
Contributions are welcome! Please feel free to submit a Pull Request.
- Issues: GitHub Issues
- Discussions: GitHub Discussions
β Star this repo if you find it useful!
Made with β€οΈ using FastAPI and MaxMind GeoLite2