Python

The Official Python client by the ipdata team. To report bugs or submit feature suggestions create an issue at https://github.com/ipdata/python

Installation

pip3 install ipdata

Basic Usage

Sample Request

from ipdata import ipdata
from pprint import pprint
# Create an instance of an ipdata object. Replace `test` with your API Key
ipdata = ipdata.IPData('test')
response = ipdata.lookup('69.78.70.144')
pprint(response)

Sample Response

The library adds a status attribute with the status code returned by the API. You can use this to troubleshoot common errors.

{'asn': 'AS6167',
'calling_code': '1',
'carrier': {'mcc': '310', 'mnc': '004', 'name': 'Verizon'},
'city': 'Farmersville',
'continent_code': 'NA',
'continent_name': 'North America',
'count': '1506',
'country_code': 'US',
'country_name': 'United States',
'currency': {'code': 'USD',
'name': 'US Dollar',
'native': '$',
'plural': 'US dollars',
'symbol': '$'},
'emoji_flag': '๐Ÿ‡บ๐Ÿ‡ธ',
'emoji_unicode': 'U+1F1FA U+1F1F8',
'flag': 'https://ipdata.co/flags/us.png',
'ip': '69.78.70.144',
'is_eu': False,
'languages': [{'name': 'English', 'native': 'English'}],
'latitude': 33.1659,
'longitude': -96.3686,
'organisation': 'Cellco Partnership DBA Verizon Wireless',
'postal': '75442',
'region': 'Texas',
'region_code': 'TX',
'status': 200,
'threat': {'is_anonymous': False,
'is_bogon': False,
'is_known_abuser': False,
'is_known_attacker': False,
'is_proxy': False,
'is_threat': False,
'is_tor': False},
'time_zone': {'abbr': 'CDT',
'current_time': '2019-04-28T17:56:59.246755-05:00',
'is_dst': True,
'name': 'America/Chicago',
'offset': '-0500'}}

Getting Only One Field

Sample Request

from ipdata import ipdata
from pprint import pprint
# Create an instance of an ipdata object. Replace `test` with your API Key
ipdata = ipdata.IPData('test')
response = ipdata.lookup('8.8.8.8', select_field='organisation')
pprint(response)

Sample Response

The library response for single field queries is formatted differently from the API. Here we return a dict with the selected field as key with the API response value and a status code attribute with the operation's status code.

{'organisation': 'Google LLC', 'status': 200}

Customizing the Response

You can pass a list of fields you'd like from the API and only those fields will be returned in the response.

Sample Request

from ipdata import ipdata
from pprint import pprint
# Create an instance of an ipdata object. Replace `test` with your API Key
ipdata = ipdata.IPData('test')
response = ipdata.lookup('8.8.8.8', fields=['ip','organisation','country_name'])
pprint(response)

Sample Response

{'country_name': 'United States',
'ip': '8.8.8.8',
'organisation': 'Google LLC',
'status': 200}

Bulk Lookups

You can lookup up to 100 IP Addresses at a time via the bulk endpoint. Note that this feature is only available to paid users.

Sample Request

from ipdata import ipdata
from pprint import pprint
# Create an instance of an ipdata object. Replace `test` with your API Key
ipdata = ipdata.IPData('test')
response = ipdata.bulk_lookup(['8.8.8.8','1.1.1.1'])
pprint(response)

Sample Response

{'responses': [{'asn': 'AS15169',
'calling_code': '1',
'city': None,
'continent_code': 'NA',
'continent_name': 'North America',
'count': '1506',
'country_code': 'US',
'country_name': 'United States',
'currency': {'code': 'USD',
'name': 'US Dollar',
'native': '$',
'plural': 'US dollars',
'symbol': '$'},
'emoji_flag': '๐Ÿ‡บ๐Ÿ‡ธ',
'emoji_unicode': 'U+1F1FA U+1F1F8',
'flag': 'https://ipdata.co/flags/us.png',
'ip': '8.8.8.8',
'is_eu': False,
'languages': [{'name': 'English', 'native': 'English'}],
'latitude': 37.751,
'longitude': -97.822,
'organisation': 'Google LLC',
'postal': None,
'region': None,
'region_code': None,
'threat': {'is_anonymous': False,
'is_bogon': False,
'is_known_abuser': False,
'is_known_attacker': False,
'is_proxy': False,
'is_threat': False,
'is_tor': False},
'time_zone': {'abbr': 'CDT',
'current_time': '2019-04-28T18:02:48.035425-05:00',
'is_dst': True,
'name': 'America/Chicago',
'offset': '-0500'}},
{'asn': 'AS13335',
'calling_code': '61',
'city': None,
'continent_code': 'OC',
'continent_name': 'Oceania',
'count': '1506',
'country_code': 'AU',
'country_name': 'Australia',
'currency': {'code': 'AUD',
'name': 'Australian Dollar',
'native': '$',
'plural': 'Australian dollars',
'symbol': 'AU$'},
'emoji_flag': '๐Ÿ‡ฆ๐Ÿ‡บ',
'emoji_unicode': 'U+1F1E6 U+1F1FA',
'flag': 'https://ipdata.co/flags/au.png',
'ip': '1.1.1.1',
'is_eu': False,
'languages': [{'name': 'English', 'native': 'English'}],
'latitude': -33.494,
'longitude': 143.2104,
'organisation': 'Cloudflare, Inc.',
'postal': None,
'region': None,
'region_code': None,
'threat': {'is_anonymous': False,
'is_bogon': False,
'is_known_abuser': False,
'is_known_attacker': False,
'is_proxy': False,
'is_threat': False,
'is_tor': False},
'time_zone': {'abbr': 'AEST',
'current_time': '2019-04-29T09:02:48.036287+10:00',
'is_dst': False,
'name': 'Australia/Sydney',
'offset': '+1000'}}],
'status': 200}

Available Fields

For a list of all available fields see Response Fields.

Errors

For a list of all possible status codes and their meanings see Status Codes.

Tests

To run all tests.

python3 test_ipdata.py