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