Skip to content
Official Python client for Ipregistry (Python 2.7+, Python 3.5+ compatible)
Python
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
ipregistry
samples
tests
.gitignore
.travis.yml
CHANGELOG.md
LICENSE.txt
README.md
ipregistry-python.iml
requirements.txt
setup.py

README.md

Ipregistry

Ipregistry Python Client Library

License Travis PyPI

This is the official Python client library for the Ipregistry IP geolocation and threat data API, allowing you to lookup your own IP address or specified ones. Responses include more than 50 data points including location, currency, timezone, threat information, and more.

Getting Started

You'll need an Ipregistry API key, which you can get along with 100,000 free lookups by signing up for a free account at https://ipregistry.co.

Installation

pip install ipregistry

Quick Start

Single IP Lookup

from ipregistry import IpregistryClient

client = IpregistryClient("YOUR_API_KEY")
ipInfo = client.lookup("54.85.132.205")
print(ipInfo)

Batch IP Lookup

from ipregistry import IpregistryClient

client = IpregistryClient("YOUR_API_KEY")
results = client.lookup(["54.85.132.205", "8.8.8.8", "2001:67c:2e8:22::c100:68b"])
for ipInfo in results:
    print(ipInfo)

Origin IP Lookup

from ipregistry import IpregistryClient

client = IpregistryClient("YOUR_API_KEY")
ipInfo = client.lookup()
print(ipInfo)

More advanced examples are available in the samples folder.

Caching

The Ipregistry client has built-in support for in-memory caching. The default cache strategy is to memoize up to 2048 lookups for at most 24h. You can change preferences as follows:

from ipregistry import DefaultCache, IpregistryClient

client = IpregistryClient("YOUR_API_KEY", cache=DefaultCache(maxsize=4096, ttl=3600))

or disable caching by passing an instance of NoCache:

from ipregistry import IpregistryClient, NoCache

client = IpregistryClient("YOUR_API_KEY", cache=NoCache())

Errors

All Ipregistry exceptions inherit IpregistryError class.

Main subtypes are ApiError and ClientError.

Errors of type ApiError include a code field that maps to the one described in the Ipregistry documentation.

Filtering bots

You might want to prevent Ipregistry API requests for crawlers or bots browsing your pages.

A manner to proceed is to identify bots using the User-Agent header. To ease this process, the library includes a utility method:

from ipregistry import UserAgent

isBot = UserAgent.isBot('YOUR_USER_AGENT_HEADER_VALUE_HERE')

Other Libraries

There are official Ipregistry client libraries available for many languages including Java, Javascript, and more.

Are you looking for an official client with a programming language or framework we do not support yet? let us know.

You can’t perform that action at this time.