Description

The IP Geolocation API supports over 190+ countries. It allows you to submit an IP address and get its location data such as the country, city, region, etc. This API is so powerful that you do not need to specify the IP address of your current location. It automatically detects the IP address the query came from. In abstract-python, the IpAPI class is used to make requests to Abstract’s IP Geolocation API. The IpAPI.ip_info() method is used to get Ip address info as seen below: IpAPI.ip_info(Optional[ip_address, fields])

Query Parameters

Below are the query parameters for this method:
ip_address
String
The ip_address you want to get location data for. The IpAPI supports both IPv4 and IPv6 addresses. If this field is left blank, the response will contain the location data of the IP address from which the request was made from.
fields
String
This parameter is used to limit the response to a few fields. For instance, you may prefer the response to only contain the country, city and region. You can add this in your query as a comma separated list like this: fields="country,city,region"

Usage

Below is a sample code to query the API:
from abstract_python import IpAPI

api_key = "your-ip-api-key"

api = IpAPI(IP_API_KEY)
print(ip.ip_info())
Below is the response object:
{
    'ip_address': '105.113.58.23', 
    'city': 'Lagos', 
    'city_geoname_id': 2332459, 
    'region': 'Lagos', 
    'region_iso_code': 'LA', 
    'region_geoname_id': 2332453, 
    'postal_code': None, 
    'country': 'Nigeria', 
    'country_code': 'NG', 
    'country_geoname_id': 2328926, 
    'country_is_eu': False, 
    'continent': 'Africa', 
    'continent_code': 'AF', 
    'continent_geoname_id': 6255146, 
    'longitude': 3.3903, 
    'latitude': 6.4474, 
    'security': {'is_vpn': False}, 
    'timezone': {
        'name': 'Africa/Lagos', 
        'abbreviation': 'WAT', 
        'gmt_offset': 1, 
        'current_time': '00:56:55', 
        'is_dst': False
    }, 
    'flag': {
        'emoji': '🇳�'', 
        'unicode': 'U+1F1F3 U+1F1EC', 
        'png': 'https://staticc.abstractapi.com/country-flags/NG_flag.png', 
        'svg': 'https://static.abstractapi.com/country-flags/NG_flag.svg'}, 
        'currency': {'currency_name': 'Naira', 'currency_code': 'NGN'}, 
        'connection': {
            'autonomous_system_number': 36873, 
            'autonomous_system_organization': 'Celtel Nigeria Limited t.a ZAIN', 
            'connection_type': 'Corporate', 
            'isp_name': 'Airtel Networks Limited', 
            'organization_name': 'Airtel Networks Limited'
        }, 
    'status': 200
}

Response Fields

ip_address
String
The ip_address of the response data.
city
String
The ip address city’s name
city_geoname_id
Strimg
The city’s geoname ID
region
String
The state or province where the city is located
region_iso_code
Char[2]
State or province’s ISO 3166-2 code.
region_geoname_id
String
State or province’s geoname ID.
postal_code
String
The IP address ZIP or postal code
country
String
The IP address country’s name
country_code
Char[2]
Country’s ISO 3166-1 alpha-2 code.
country_geoname_id
String
Country’s geoname ID.
country_is_eu
Boolean
A boolean value that confirms if the country is in the European Union (EU). True if yes, and False is not.
continent
String
The IP address continent’s name
continent_code
Char[2]
A 2 letter continent code: AF, AS, EU, NA, OC, SA, AN.
continent_geoname_id
String
Continent’s geoname ID.
longitude
Float
A decimal value of the IP address longitude
latitude
Float
A decimal value of the IP address latitude
security.is_vpn
Boolean
A boolean value that confirms whether the IP address is using from a VPN or using a proxy
timezone.name
String
Timezone’s name from the IANA Time Zone Database.
timezone.abbreviation
String
Timezone’s abbreviation, also from the IANA Time Zone Database.
timezone.gmt_offset
String
Timezone’s offset from Greenwich Mean Time (GMT).
timezone.current_time
String
Current time in the local time zone.
timezone.is_dst
Boolean
True if the location is currently in Daylight Savings Time (DST)
flag.svg
String
Link to a hosted version of the country’s flag in SVG format.
flag.png
String
Link to a hosted version of the country’s flag in PNG format.
flag.emoji
String
Link to a hosted version of the country’s flag in SVG format.
flag.unicode
Boolean
Country’s flag in unicode.
currency.currency_name
String
The currency’s name.
currency.currency_code
String
The currency’s code in ISO 4217 format.
connection.connection_type
String
Type of network connection: Dialup, Cable/DSL, Cellular, Corporate.
connection.autonomous_system_number
Uint32
Autonomous System number.
connection.isp_name
String
The Internet Service Provider (ISP) name you used when sending the query.
connection.organization_name
String
Organization name.

Specify Ip address

You can also specify a unique IP address in your query to get its location data. Below is a code snippet to query the API by Ip address:
from abstract_python import IpAPI

api_key = "your-ip-api-key"
ip_address = "105.113.58.23"

api = IpAPI(IP_API_KEY)
print(ip.ip_info(ip_address))
The code above uses the IP address in the previous response. Below is the response object for the code above:
{
    'ip_address': '105.113.58.23', 
    'city': 'Lagos', 
    'city_geoname_id': 2332459, 
    'region': 'Lagos', 
    'region_iso_code': 'LA', 
    'region_geoname_id': 2332453, 
    'postal_code': None, 
    'country': 'Nigeria', 
    'country_code': 'NG', 
    'country_geoname_id': 2328926, 
    'country_is_eu': False, 
    'continent': 'Africa', 
    'continent_code': 'AF', 
    'continent_geoname_id': 6255146, 
    'longitude': 3.3903, 
    'latitude': 6.4474, 
    'security': {'is_vpn': False}, 
    'timezone': {
        'name': 'Africa/Lagos', 
        'abbreviation': 'WAT', 
        'gmt_offset': 1, 
        'current_time': '00:56:55', 
        'is_dst': False
    }, 
    'flag': {
        'emoji': '🇳�'', 
        'unicode': 'U+1F1F3 U+1F1EC', 
        'png': 'https://staticc.abstractapi.com/country-flags/NG_flag.png', 
        'svg': 'https://static.abstractapi.com/country-flags/NG_flag.svg'}, 
        'currency': {'currency_name': 'Naira', 'currency_code': 'NGN'}, 'connection': {'autonomous_system_number': 36873, 'autonomous_system_organization': 'Celtel Nigeria Limited t.a ZAIN', 'connection_type': 'Corporate', 'isp_name': 'Airtel Networks Limited', 'organization_name': 'Airtel Networks Limited'}, 'status': 200}

Limit response fields

The IpAPI also allows you to limit the response data to certain fields. Below is an example code to limit response data using the fields argument:
from abstract_python import IpAPI

api_key = "your-ip-api-key"
ip_address = "105.113.58.23"
fields = "ip_address, city, region, region_geoname_id, country"

api = IpAPI(IP_API_KEY)
print(ip.ip_info(ip_address, fields=fields))
Below is the response object:
{
    'ip_address': '105.113.58.23', 
    'city': 'Lagos',  
    'region': 'Lagos', 
    'region_geoname_id': 2332453, 
    'country': 'Nigeria',
    'status': 200
}

Error messages

Refer to this page for all possible error messages you may encounter while using the IpAPI class.