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/issues/new

Official Python client library and CLI for the ipdata API

This is a Python client and command line interface (CLI) for the ipdata.co IP Geolocation API. ipdata offers a fast, highly-available API to enrich IP Addresses with Location, Company, Threat Intelligence and numerous other data attributes.

Note that you need an API Key to use this package. You can get a free one with a 1,500 daily request limit by Signing up here.

Visit our Documentation for more examples and tutorials.

asciicast

Installation

pip install ipdata

Library Usage

Looking Up the Calling IP Address

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()
pprint(response)

Looking Up any IP Address

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)

Getting only one field

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)

Response

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

Getting a number of specific fields

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)

Response

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

Bulk Lookups

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)

Available Fields

A list of all the fields returned by the API is maintained at Response Fields

Errors

A list of possible errors is available at Status Codes

Tests

To run all tests

python -m unittest