ipregistry


Nameipregistry JSON
Version 4.0.0 PyPI version JSON
download
home_pagehttps://ipregistry.co
SummaryOfficial Python library for Ipregistry
upload_time2024-06-14 08:44:19
maintainerNone
docs_urlNone
authorIpregistry Team
requires_python>=3.8
licenseApache-2.0
keywords ipinfo ipregistry ip-address ip-data ip-geolocation threat-detection user-agent-parsing
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [<img src="https://cdn.ipregistry.co/icons/favicon-96x96.png" alt="Ipregistry" width="64"/>](https://ipregistry.co/) 
# Ipregistry Python Client Library

[![License](http://img.shields.io/:license-apache-blue.svg)](LICENSE)
[![Actions Status](https://github.com/ipregistry/ipregistry-python/workflows/Tests/badge.svg)](https://github.com/ipregistry/ipregistry-python/actions)
[![PyPI](https://img.shields.io/pypi/v/ipregistry)](https://pypi.org/project/ipregistry/)

This is the official Python client library for the [Ipregistry](https://ipregistry.co) 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](https://ipregistry.co).

### Installation

```
pip install ipregistry
```

### Quick Start

#### Single IP Lookup

```python
from ipregistry import IpregistryClient

client = IpregistryClient("YOUR_API_KEY")
response = client.lookup_ip("54.85.132.205")

# Printing whole response
print(response)

# Retrieving a specific field
country_code = response.data.location.country.code

# Getting number of credits consumed or remaining
credits_consumed = response.credits.consumed
credits_remaining = response.credits.remaining
```

#### Single ASN Lookup

```python
from ipregistry import IpregistryClient

client = IpregistryClient("YOUR_API_KEY")
response = client.lookup_asn(42)
print(response.credits.consumed)
print(response.data.prefixes)
print(response.data.relationships)
```

#### Batch IP Lookup

```python
from ipregistry import IpregistryClient

client = IpregistryClient("YOUR_API_KEY")
response = client.batch_lookup_ips(["54.85.132.205", "8.8.8.8", "2001:67c:2e8:22::c100:68b"])
for ip_info in response.data:
    print(ip_info)
```

#### Origin IP Lookup

```python
from ipregistry import IpregistryClient

client = IpregistryClient("YOUR_API_KEY")
response = client.origin_lookup_ip()
print(response.data)
```

#### User-Agent Parsing

```python
from ipregistry import IpregistryClient

client = IpregistryClient("YOUR_API_KEY")
response = client.parse_user_agent('Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36')
print(response.data)
```

More advanced examples are available in the [samples](https://github.com/ipregistry/ipregistry-python/tree/master/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`:

```python
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`:

```python
from ipregistry import IpregistryClient, NoCache

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

### European Union Base URL

With the ever-increasing concerns about data privacy and security, we recognize the importance of providing our European users with a dedicated API base URL:

```python
from ipregistry import IpregistryClient, NoCache

client = IpregistryClient(IpregistryConfig("YOUR_API_KEY").with_eu_base_url())
```

Using this base URL your requests are handled by the closest cluster of nodes in the European Union.

### 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](https://ipregistry.co/docs/errors).

### 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:

```python
from ipregistry import UserAgents

is_bot = UserAgents.is_bot('YOUR_USER_AGENT_HEADER_VALUE_HERE')
```

## Other Libraries

There are official Ipregistry client libraries available for many languages including 
[Java](https://github.com/ipregistry/ipregistry-java), 
[Javascript](https://github.com/ipregistry/ipregistry-javascript), and more.

Are you looking for an official client with a programming language or framework we do not support yet? 
[let us know](mailto:support@ipregistry.co).

            

Raw data

            {
    "_id": null,
    "home_page": "https://ipregistry.co",
    "name": "ipregistry",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "ipinfo, ipregistry, ip-address, ip-data, ip-geolocation, threat-detection, user-agent-parsing",
    "author": "Ipregistry Team",
    "author_email": "support@ipregistry.co",
    "download_url": "https://files.pythonhosted.org/packages/3e/11/458b5ca7cbda087130f278ae34bac5092fbd476f0769684d82da1da946db/ipregistry-4.0.0.tar.gz",
    "platform": null,
    "description": "[<img src=\"https://cdn.ipregistry.co/icons/favicon-96x96.png\" alt=\"Ipregistry\" width=\"64\"/>](https://ipregistry.co/) \n# Ipregistry Python Client Library\n\n[![License](http://img.shields.io/:license-apache-blue.svg)](LICENSE)\n[![Actions Status](https://github.com/ipregistry/ipregistry-python/workflows/Tests/badge.svg)](https://github.com/ipregistry/ipregistry-python/actions)\n[![PyPI](https://img.shields.io/pypi/v/ipregistry)](https://pypi.org/project/ipregistry/)\n\nThis is the official Python client library for the [Ipregistry](https://ipregistry.co) IP geolocation and threat data API, \nallowing you to lookup your own IP address or specified ones. Responses return multiple data points including carrier, \ncompany, currency, location, timezone, threat information, and more.\n\nStarting version 3 of the library, support for Python 2 has been dropped and the library requires Python 3.6+.\n\n## Getting Started\n\nYou'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](https://ipregistry.co).\n\n### Installation\n\n```\npip install ipregistry\n```\n\n### Quick Start\n\n#### Single IP Lookup\n\n```python\nfrom ipregistry import IpregistryClient\n\nclient = IpregistryClient(\"YOUR_API_KEY\")\nresponse = client.lookup_ip(\"54.85.132.205\")\n\n# Printing whole response\nprint(response)\n\n# Retrieving a specific field\ncountry_code = response.data.location.country.code\n\n# Getting number of credits consumed or remaining\ncredits_consumed = response.credits.consumed\ncredits_remaining = response.credits.remaining\n```\n\n#### Single ASN Lookup\n\n```python\nfrom ipregistry import IpregistryClient\n\nclient = IpregistryClient(\"YOUR_API_KEY\")\nresponse = client.lookup_asn(42)\nprint(response.credits.consumed)\nprint(response.data.prefixes)\nprint(response.data.relationships)\n```\n\n#### Batch IP Lookup\n\n```python\nfrom ipregistry import IpregistryClient\n\nclient = IpregistryClient(\"YOUR_API_KEY\")\nresponse = client.batch_lookup_ips([\"54.85.132.205\", \"8.8.8.8\", \"2001:67c:2e8:22::c100:68b\"])\nfor ip_info in response.data:\n    print(ip_info)\n```\n\n#### Origin IP Lookup\n\n```python\nfrom ipregistry import IpregistryClient\n\nclient = IpregistryClient(\"YOUR_API_KEY\")\nresponse = client.origin_lookup_ip()\nprint(response.data)\n```\n\n#### User-Agent Parsing\n\n```python\nfrom ipregistry import IpregistryClient\n\nclient = IpregistryClient(\"YOUR_API_KEY\")\nresponse = client.parse_user_agent('Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36')\nprint(response.data)\n```\n\nMore advanced examples are available in the [samples](https://github.com/ipregistry/ipregistry-python/tree/master/samples) \nfolder.\n\n### Caching\n\nThis Ipregistry client library has built-in support for in-memory caching. By default caching is disabled. \nBelow are examples to enable and configure a caching strategy. Once enabled, default cache strategy is to memoize up to \n2048 lookups for at most 10min. You can change preferences as follows:\n\n#### Enabling caching\n\nEnable caching by passing an instance of `InMemoryCache`:\n\n```python\nfrom ipregistry import InMemoryCache, IpregistryClient\n\nclient = IpregistryClient(\"YOUR_API_KEY\", cache=InMemoryCache(maxsize=2048, ttl=600))\n```\n\n#### Disabling caching\n\nDisable caching by passing an instance of `NoCache`:\n\n```python\nfrom ipregistry import IpregistryClient, NoCache\n\nclient = IpregistryClient(\"YOUR_API_KEY\", cache=NoCache())\n```\n\n### European Union Base URL\n\nWith the ever-increasing concerns about data privacy and security, we recognize the importance of providing our European users with a dedicated API base URL:\n\n```python\nfrom ipregistry import IpregistryClient, NoCache\n\nclient = IpregistryClient(IpregistryConfig(\"YOUR_API_KEY\").with_eu_base_url())\n```\n\nUsing this base URL your requests are handled by the closest cluster of nodes in the European Union.\n\n### Errors\n\nAll Ipregistry exceptions inherit `IpregistryError` class.\n\nMain subtypes are `ApiError` and `ClientError`.\n\nErrors of type _ApiError_ include a code field that maps to the one described in the [Ipregistry documentation](https://ipregistry.co/docs/errors).\n\n### Filtering bots\n\nYou might want to prevent Ipregistry API requests for crawlers or bots browsing your pages.\n\nA manner to proceed is to identify bots using the `User-Agent` header. \nTo ease this process, the library includes a utility method:\n\n```python\nfrom ipregistry import UserAgents\n\nis_bot = UserAgents.is_bot('YOUR_USER_AGENT_HEADER_VALUE_HERE')\n```\n\n## Other Libraries\n\nThere are official Ipregistry client libraries available for many languages including \n[Java](https://github.com/ipregistry/ipregistry-java), \n[Javascript](https://github.com/ipregistry/ipregistry-javascript), and more.\n\nAre you looking for an official client with a programming language or framework we do not support yet? \n[let us know](mailto:support@ipregistry.co).\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "Official Python library for Ipregistry",
    "version": "4.0.0",
    "project_urls": {
        "Homepage": "https://ipregistry.co",
        "Repository": "https://github.com/ipregistry/ipregistry-python"
    },
    "split_keywords": [
        "ipinfo",
        " ipregistry",
        " ip-address",
        " ip-data",
        " ip-geolocation",
        " threat-detection",
        " user-agent-parsing"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b91ed0fe6e377072126c6ba79294bb98f2d562c9066cb9b4246bc76fe0a190a3",
                "md5": "7a2ce3605abb934103111241d02c3401",
                "sha256": "a2013b7c287e490e035c62aebca597cc0084984302cf2adbbeb7d9d11be474c6"
            },
            "downloads": -1,
            "filename": "ipregistry-4.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7a2ce3605abb934103111241d02c3401",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 15454,
            "upload_time": "2024-06-14T08:44:18",
            "upload_time_iso_8601": "2024-06-14T08:44:18.371821Z",
            "url": "https://files.pythonhosted.org/packages/b9/1e/d0fe6e377072126c6ba79294bb98f2d562c9066cb9b4246bc76fe0a190a3/ipregistry-4.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3e11458b5ca7cbda087130f278ae34bac5092fbd476f0769684d82da1da946db",
                "md5": "b6a1a5fcec2949a5c6761db2cb79ef4b",
                "sha256": "f7041e36657e24cc57d004a7ef76fd60859b9760f9d5a16a912f9f3ec1d2e45a"
            },
            "downloads": -1,
            "filename": "ipregistry-4.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "b6a1a5fcec2949a5c6761db2cb79ef4b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 13680,
            "upload_time": "2024-06-14T08:44:19",
            "upload_time_iso_8601": "2024-06-14T08:44:19.912745Z",
            "url": "https://files.pythonhosted.org/packages/3e/11/458b5ca7cbda087130f278ae34bac5092fbd476f0769684d82da1da946db/ipregistry-4.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-14 08:44:19",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ipregistry",
    "github_project": "ipregistry-python",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "ipregistry"
}
        
Elapsed time: 0.31797s