IP Geolocation for Python (geolocation-api-python)
Python library for Abstract free IP Geolocation API.
Full documentation can be found on Abstract IP Geolocation API page.
Getting started
Getting started with Abstract IP Geolocation API is very simple, you just need to install the library into your project as follow:
pip install abstract-ip-geolocation-api
From there you can then call the geolocationapi as follow:
import importlib
abstract_ip_geolocation_api = importlib.import_module("abstract-ip-geolocation-api")
geolocation_api = abstract_ip_geolocation_api.v1('YOUR_API_KEY')
location_data = geolocation_api.geolocate(ip_address="ANY_IP_ADDRESS")
if 'ip_address' in location_data:
country = location_data['country']
city = location_data['city']
print(country)
elif 'error' in location_data:
error = location_data['error']
print(error)
else:
print('No location data available for this IP')