> ## Documentation Index
> Fetch the complete documentation index at: https://rilwanorganization.mintlify.app/llms.txt
> Use this file to discover all available pages before exploring further.

# 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:

<ParamField path="ip_address" type="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.
</ParamField>

<ParamField path="fields" type="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"`
</ParamField>

## Usage

Below is a sample code to query the API:

```python theme={null}
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:

```python theme={null}
{
    '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

<ResponseField name="ip_address" type="String">
  The ip\_address of the response data.
</ResponseField>

<ResponseField name="city" type="String">
  The ip address city's name
</ResponseField>

<ResponseField name="city_geoname_id" type="Strimg">
  The city's geoname ID
</ResponseField>

<ResponseField name="region" type="String">
  The state or province where the city is located
</ResponseField>

<ResponseField name="region_iso_code" type="Char[2]">
  State or province’s ISO 3166-2 code.
</ResponseField>

<ResponseField name="region_geoname_id" type="String">
  State or province’s geoname ID.
</ResponseField>

<ResponseField name="postal_code" type="String">
  The IP address ZIP or postal code
</ResponseField>

<ResponseField name="country" type="String">
  The IP address country's name
</ResponseField>

<ResponseField name="country_code" type="Char[2]">
  Country’s ISO 3166-1 alpha-2 code.
</ResponseField>

<ResponseField name="country_geoname_id" type="String">
  Country’s geoname ID.
</ResponseField>

<ResponseField name="country_is_eu" type="Boolean">
  A boolean value that confirms if the country is in the European Union (EU).
  True if yes, and False is not.
</ResponseField>

<ResponseField name="continent" type="String">
  The IP address continent's name
</ResponseField>

<ResponseField name="continent_code" type="Char[2]">
  A 2 letter continent code: AF, AS, EU, NA, OC, SA, AN.
</ResponseField>

<ResponseField name="continent_geoname_id" type="String">
  Continent’s geoname ID.
</ResponseField>

<ResponseField name="longitude" type="Float">
  A decimal value of the IP address longitude
</ResponseField>

<ResponseField name="latitude" type="Float">
  A decimal value of the IP address latitude
</ResponseField>

<ResponseField name="security.is_vpn" type="Boolean">
  A boolean value that confirms whether the IP address is using from a VPN or using a proxy
</ResponseField>

<ResponseField name="timezone.name" type="String">
  Timezone’s name from the IANA Time Zone Database.
</ResponseField>

<ResponseField name="timezone.abbreviation" type="String">
  Timezone’s abbreviation, also from the IANA Time Zone Database.
</ResponseField>

<ResponseField name="timezone.gmt_offset" type="String">
  Timezone’s offset from Greenwich Mean Time (GMT).
</ResponseField>

<ResponseField name="timezone.current_time" type="String">
  Current time in the local time zone.
</ResponseField>

<ResponseField name="timezone.is_dst" type="Boolean">
  True if the location is currently in Daylight Savings Time (DST)
</ResponseField>

<ResponseField name="flag.svg" type="String">
  Link to a hosted version of the country’s flag in SVG format.
</ResponseField>

<ResponseField name="flag.png" type="String">
  Link to a hosted version of the country’s flag in PNG format.
</ResponseField>

<ResponseField name="flag.emoji" type="String">
  Link to a hosted version of the country’s flag in SVG format.
</ResponseField>

<ResponseField name="flag.unicode" type="Boolean">
  Country’s flag in unicode.
</ResponseField>

<ResponseField name="currency.currency_name" type="String">
  The currency’s name.
</ResponseField>

<ResponseField name="currency.currency_code" type="String">
  The currency’s code in ISO 4217 format.
</ResponseField>

<ResponseField name="connection.connection_type" type="String">
  Type of network connection: Dialup, Cable/DSL, Cellular, Corporate.
</ResponseField>

<ResponseField name="connection.autonomous_system_number" type="Uint32">
  Autonomous System number.
</ResponseField>

<ResponseField name="connection.isp_name" type="String">
  The Internet Service Provider (ISP) name you used when sending the query.
</ResponseField>

<ResponseField name="connection.organization_name" type="String">
  Organization name.
</ResponseField>

## 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:

```python theme={null}
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:

```python theme={null}
{
    '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:

```python theme={null}
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:

```python theme={null}
{
    'ip_address': '105.113.58.23', 
    'city': 'Lagos',  
    'region': 'Lagos', 
    'region_geoname_id': 2332453, 
    'country': 'Nigeria',
    'status': 200
}
```

## Error messages

Refer to [this page](https://docs.abstractapi.com/ip-geolocation#response-and-error-codes) for all possible error messages you may encounter while using the `IpAPI` class.
