Ip API
This API allows you to get the complete location data of an IP address.
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:
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.
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:
Below is the response object:
Response Fields
The ip_address of the response data.
The ip address city’s name
The city’s geoname ID
The state or province where the city is located
State or province’s ISO 3166-2 code.
State or province’s geoname ID.
The IP address ZIP or postal code
The IP address country’s name
Country’s ISO 3166-1 alpha-2 code.
Country’s geoname ID.
A boolean value that confirms if the country is in the European Union (EU). True if yes, and False is not.
The IP address continent’s name
A 2 letter continent code: AF, AS, EU, NA, OC, SA, AN.
Continent’s geoname ID.
A decimal value of the IP address longitude
A decimal value of the IP address latitude
A boolean value that confirms whether the IP address is using from a VPN or using a proxy
Timezone’s name from the IANA Time Zone Database.
Timezone’s abbreviation, also from the IANA Time Zone Database.
Timezone’s offset from Greenwich Mean Time (GMT).
Current time in the local time zone.
True if the location is currently in Daylight Savings Time (DST)
Link to a hosted version of the country’s flag in SVG format.
Link to a hosted version of the country’s flag in PNG format.
Link to a hosted version of the country’s flag in SVG format.
Country’s flag in unicode.
The currency’s name.
The currency’s code in ISO 4217 format.
Type of network connection: Dialup, Cable/DSL, Cellular, Corporate.
Autonomous System number.
The Internet Service Provider (ISP) name you used when sending the query.
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:
The code above uses the IP address in the previous response. Below is the response object for the code above:
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:
Below is the response object:
Error messages
Refer to this page for all possible error messages you may encounter while using the IpAPI
class.