Official Python library for Ipregistry
Project description
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 multiple data points including carrier, company, currency, location, timezone, threat information, and more.
Starting version 3 of the library, support for Python 2 has been dropped and the library requires Python 3.6+.
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
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:
Enabling caching
Enable caching by passing an instance of InMemoryCache
:
from ipregistry import InMemoryCache, IpregistryClient
client = IpregistryClient("YOUR_API_KEY", cache=InMemoryCache(maxsize=2048, ttl=600))
Disabling caching
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.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for ipregistry-3.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b1303c5d38130bedf123b52992408fd55577142bf3a0ed25129deffd976062f3 |
|
MD5 | e552f720c60aaf543f457ea4c292add1 |
|
BLAKE2b-256 | 02c99e96d519c4ed069c0d353af88227a12b1f5c33e9a1700030a041e71c9c53 |