This is a Flask web application that provides geolocation information for a given IP address using MaxMind's GeoIP2 databases.
- Install dependencies using
pip
:
pip install flask maxminddb
- Download the GeoIP2 databases from MaxMind's website:
- Update the paths to the downloaded databases in the
city_db_path
,country_db_path
, andasn_db_path
variables in theapp.py
file:
city_db_path = 'GeoLite2-City.mmdb'
country_db_path = 'GeoLite2-Country.mmdb'
asn_db_path = 'GeoLite2-ASN.mmdb'
- Start the Flask application:
python app.py
The GeoIP2 Geolocation API can be deployed in various ways, depending on your requirements and preferences. Here are a few options:
For local development, you can simply run the Flask application on your local machine using the python app.py
command as mentioned in the setup section.
You can create a virtual environment for the Flask application and deploy it in a virtual environment. Here's an example:
- Create and activate a virtual environment:
python -m venv myenv
source myenv/bin/activate # On Windows: myenv\Scripts\activate
- Install dependencies inside the virtual environment:
pip install flask maxminddb
-
Update the paths to the downloaded databases in the
city_db_path
,country_db_path
, andasn_db_path
variables in theapp.py
file. -
Start the Flask application:
python app.py
You can also deploy the GeoIP2 Geolocation API in a Docker container. Here's an example:
-
Install Docker on your machine following the official Docker documentation.
-
Build a Docker image from the provided Dockerfile:
docker build -t geoip2-api .
- Run a Docker container from the built image:
docker run -p 5000:5000 -d geoip2-api
This will run the Flask application inside a Docker container, and you can access it at http://localhost:5000
in your web browser.
[API endpoint details here]
This project is licensed under the MIT License. See LICENSE for more information.