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.

Installation

1
pip install ipdata
Copied!

Library Usage

Looking Up the Calling IP Address

1
from ipdata import ipdata
2
from pprint import pprint
3
# Create an instance of an ipdata object. Replace `test` with your API Key
4
ipdata = ipdata.IPData('test')
5
response = ipdata.lookup()
6
pprint(response)
Copied!

Looking Up any IP Address

1
from ipdata import ipdata
2
from pprint import pprint
3
# Create an instance of an ipdata object. Replace `test` with your API Key
4
ipdata = ipdata.IPData('test')
5
response = ipdata.lookup('69.78.70.144')
6
pprint(response)
Copied!

Getting only one field

1
from ipdata import ipdata
2
from pprint import pprint
3
# Create an instance of an ipdata object. Replace `test` with your API Key
4
ipdata = ipdata.IPData('test')
5
response = ipdata.lookup('8.8.8.8', select_field='organisation')
6
pprint(response)
Copied!
Response
1
{'organisation': 'Google LLC', 'status': 200}
Copied!

Getting a number of specific fields

1
from ipdata import ipdata
2
from pprint import pprint
3
# Create an instance of an ipdata object. Replace `test` with your API Key
4
ipdata = ipdata.IPData('test')
5
response = ipdata.lookup('8.8.8.8',fields=['ip','organisation','country_name'])
6
pprint(response)
Copied!
Response
1
{'country_name': 'United States',
2
'ip': '8.8.8.8',
3
'organisation': 'Google LLC',
4
'status': 200}
Copied!

Bulk Lookups

1
from ipdata import ipdata
2
from pprint import pprint
3
# Create an instance of an ipdata object. Replace `test` with your API Key
4
ipdata = ipdata.IPData('test')
5
response = ipdata.bulk_lookup(['8.8.8.8','1.1.1.1'])
6
pprint(response)
Copied!

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
1
python -m unittest
Copied!
Last modified 1yr ago