Self-hosted IP geolocation API that works completely offline!
1.4K
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:
# {
# "code": "US",
# "country": "United States",
# "city": "Mountain View",
# "lat": 37.4056,
# "lon": -122.0775,
# "tz": "America/Los_Angeles",
# "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",
"city": "Mountain View",
"lat": 37.4056,
"lon": -122.0775,
"tz": "America/Los_Angeles",
"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:
git clone https://github.com/Malith-Rukshan/geoip-api.git
cd geoip-api
docker build -t geoip-api .
docker run -p 8000:8000 geoip-api
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
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.
Contributions are welcome! Please feel free to submit a Pull Request.
git checkout -b feature/amazing-feature)git commit -m 'Add some amazing feature')git push origin feature/amazing-feature)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:
π§βπ» Built with π by Malith Rukshanβ
Content type
Image
Digest
sha256:4429b47f0β¦
Size
102.7 MB
Last updated
over 1 year ago
docker pull malithrukshan/geoip-api