IP Geolocation API from Abstract to geolocate any IP
Project description
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 abstract ip geolocation api module
import importlib
abstract_ip_geolocation_api = importlib.import_module("abstract-ip-geolocation-api")
# Initiate the geolocation api with a free API key retrieved on https://www.abstractapi.com/ip-geolocation-api
geolocation_api = abstract_ip_geolocation_api.v1('YOUR_API_KEY')
# Fetch location data for a given IP
# Note: If you don't provide an ip_address value, then the requester IP will be used
location_data = geolocation_api.geolocate(ip_address="ANY_IP_ADDRESS")
# Process location data and potential errors
if 'ip_address' in location_data:
# Location data has been successfully retrieved
country = location_data['country']
city = location_data['city']
print(country)
elif 'error' in location_data:
# Handle Abstract related errors
error = location_data['error']
print(error)
else:
# No location data available for this IP
print('No location data available for this IP')
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for abstract-ip-geolocation-api-1.5.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2eb2e5fca04c5b32c889667971a6914cb987cc43b2d0fe3da1dc6613164ca2a8 |
|
MD5 | 794fadec2f0a385a65e5160757c5e804 |
|
BLAKE2b-256 | 493f9e8cd1ec3f7fc1f685634ed7a6168be42d59e3312ff4e3a0a3f7150ff215 |
Close
Hashes for abstract_ip_geolocation_api-1.5.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d469897169db4592a4487964f2e0dd0d22417e56dca07edc03c859bc41364cd |
|
MD5 | 97ac594c8daee7b19e7989fcd3e4bc27 |
|
BLAKE2b-256 | f73b566b7fffa516e203c27d3fc49b46629154bd8a50b979b7fedc3d9831bf35 |