Powered by MaxMind's GeoLite2 databases γ
- π Fast and reliable IP geolocation lookups
- π Self-hosted solution with no external API dependencies
- π οΈ Dual functionality: Python package and REST API
- π³ Easy deployment with Docker and cloud platforms
- π Get country, city, coordinates, timezone, ISP, and ASN data
- π¨ Beautiful, interactive demo UI for testing
- π Built with FastAPI for high performance
- π¦ Automatic GeoLite2 database downloads and updates
pip install geoip-py
from geoip_api import GeoIPLookup
# Initialize the lookup service (downloads DB files if needed)
lookup = GeoIPLookup(download_if_missing=True)
# Look up an IP address
result = lookup.lookup('8.8.8.8')
print(result)
# Output:
# {
# "ip": "8.8.8.8",
# "code": "US",
# "country": "United States",
# "continent": "North America",
# "continent_code": "NA",
# "city": "Mountain View",
# "lat": 37.4056,
# "lon": -122.0775,
# "tz": "America/Los_Angeles",
# "currency": "USD",
# "isp": "Google LLC",
# "asn": 15169
# }
β Demo : https://geoip-api.malith.dev/
# Simple path parameter
https://your-domain.com/8.8.8.8
# Query parameter
https://your-domain.com/?ip=8.8.8.8
https://your-domain.com/api/v1/geoip/lookup/8.8.8.8
{
"ip": "8.8.8.8",
"code": "US",
"country": "United States",
"continent": "North America",
"continent_code": "NA",
"city": "Mountain View",
"lat": 37.4056,
"lon": -122.0775,
"tz": "America/Los_Angeles",
"currency": "USD",
"isp": "Google LLC",
"asn": 15169
}
One-click deployment to popular platforms:
The fastest way to deploy your own GeoIP API:
docker pull malithrukshan/geoip-api
docker run -p 8000:8000 malithrukshan/geoip-api
Your API will be available at http://localhost:8000
Create a docker-compose.yml
file:
version: '3.8'
services:
geoip-api:
image: malithrukshan/geoip-api
ports:
- "8000:8000"
# volumes:
# - ./data:/app/api/db
environment:
- ENVIRONMENT=production
Then run:
docker-compose up -d
If you want to build and run the Docker image from source:
- Clone the repository
git clone https://github.com/Malith-Rukshan/geoip-api.git cd geoip-api
- Build the Docker image
docker build -t geoip-api .
- Run the container
docker run -p 8000:8000 geoip-api
- Access the API at http://localhost:8000
- Python 3.9+
- pip
-
Clone the repository
git clone https://github.com/Malith-Rukshan/geoip-api.git cd geoip-api
-
Install dependencies
pip install -r requirements/dev.txt pip install -e .
-
Download GeoIP databases (optional, will be downloaded automatically if needed)
mkdir -p ~/.geoip_api curl -L -o ~/.geoip_api/GeoLite2-City.mmdb https://github.com/P3TERX/GeoLite.mmdb/raw/download/GeoLite2-City.mmdb curl -L -o ~/.geoip_api/GeoLite2-ASN.mmdb https://github.com/P3TERX/GeoLite.mmdb/raw/download/GeoLite2-ASN.mmdb
-
Run the FastAPI application
uvicorn api.main:app --reload
-
Visit http://localhost:8000 to see the API in action
pytest
black --check src tests api
mypy src tests api
- Security & Compliance: Enhance security systems with IP-based threat detection while maintaining data sovereignty
- Content Localization: Deliver region-specific content based on visitor location without sharing user data
- Analytics: Analyze traffic patterns and user demographics with geographic data that remains within your infrastructure
- Fraud Prevention: Identify suspicious login attempts based on geographic anomalies
- Development Environment: Use a local GeoIP service in your development environment without external API dependencies
This project is licensed under the MIT License - see the LICENSE file for details.
This project uses GeoLite2 data created by MaxMind, available from https://www.maxmind.com. The GeoLite2 databases are licensed under the Creative Commons Attribution-ShareAlike 4.0 International License.
- GeoLite2 databases provided by MaxMind
- Mirror of GeoLite2 databases maintained by P3TERX
- Built with FastAPI and Python
- Powered by geoip2 library
πΊπ³ Flags By : Animated Country Flags
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
If you found this project helpful, please give it a β on GitHub. This helps more developers discover the project! π«Ά
If you have any questions, feedback, or just want to say hi, you can reach out to me:
- Email: hello@malith.dev
- GitHub: @Malith-Rukshan
π§βπ» Built with π by Malith Rukshan