Official Python library for Ipregistry
Ipregistry Python Client Library
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 return up to 65 data points including location, currency, timezone, threat information, and more.
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.
pip install ipregistry
Single IP Lookup
from ipregistry import IpregistryClient client = IpregistryClient("YOUR_API_KEY") ipInfo = client.lookup("184.108.40.206") print(ipInfo)
Batch IP Lookup
from ipregistry import IpregistryClient client = IpregistryClient("YOUR_API_KEY") results = client.lookup(["220.127.116.11", "18.104.22.168", "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.
This Ipregistry client library has built-in support for in-memory caching. By default caching is disabled. Below are examples to enable and configure a caching strategy. Once enabled, default cache strategy is to memoize up to 2048 lookups for at most 10min. You can change preferences as follows:
Enable caching by passing an instance of
from ipregistry import DefaultCache, IpregistryClient client = IpregistryClient("YOUR_API_KEY", cache=DefaultCache(maxsize=2048, ttl=600))
Disable caching by passing an instance of
from ipregistry import IpregistryClient, NoCache client = IpregistryClient("YOUR_API_KEY", cache=NoCache())
All Ipregistry exceptions inherit
Main subtypes are
Errors of type ApiError include a code field that maps to the one described in the Ipregistry documentation.
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
To ease this process, the library includes a utility method:
from ipregistry import UserAgent isBot = UserAgent.isBot('YOUR_USER_AGENT_HEADER_VALUE_HERE')
Are you looking for an official client with a programming language or framework we do not support yet? let us know.
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size ipregistry-2.0.1-py3-none-any.whl (11.9 kB)||File type Wheel||Python version py3||Upload date||Hashes View|
|Filename, size ipregistry-2.0.1.tar.gz (5.9 kB)||File type Source||Python version None||Upload date||Hashes View|
Hashes for ipregistry-2.0.1-py3-none-any.whl