ipregistry 3.2.0__tar.gz → 5.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,227 @@
1
+ Metadata-Version: 2.4
2
+ Name: ipregistry
3
+ Version: 5.0.0
4
+ Summary: Official Python library for Ipregistry
5
+ Keywords: ipinfo,ipregistry,ip-address,ip-data,ip-geolocation,threat-detection,user-agent-parsing
6
+ Author: Ipregistry Team, Laurent Pellegrino
7
+ Author-email: Ipregistry Team <support@ipregistry.co>, Laurent Pellegrino <laurent.pellegrino@ipregistry.co>
8
+ License-Expression: Apache-2.0
9
+ License-File: LICENSE.txt
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Programming Language :: Python :: 3.14
18
+ Classifier: Topic :: Internet
19
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
20
+ Classifier: Typing :: Typed
21
+ Requires-Dist: cachetools>=7.1.4,<8.0.0
22
+ Requires-Dist: pydantic>=2.13.4,<3.0.0
23
+ Requires-Dist: requests>=2.34.2,<3.0.0
24
+ Requires-Dist: httpx>=0.28.1,<0.29.0 ; extra == 'async'
25
+ Requires-Python: >=3.10
26
+ Project-URL: Homepage, https://ipregistry.co
27
+ Project-URL: Repository, https://github.com/ipregistry/ipregistry-python
28
+ Provides-Extra: async
29
+ Description-Content-Type: text/markdown
30
+
31
+ [<img src="https://cdn.ipregistry.co/icons/favicon-96x96.png" alt="Ipregistry" width="64"/>](https://ipregistry.co/)
32
+ # Ipregistry Python Client Library
33
+
34
+ [![License](http://img.shields.io/:license-apache-blue.svg)](LICENSE)
35
+ [![Actions Status](https://github.com/ipregistry/ipregistry-python/workflows/Tests/badge.svg)](https://github.com/ipregistry/ipregistry-python/actions)
36
+ [![PyPI](https://img.shields.io/pypi/v/ipregistry)](https://pypi.org/project/ipregistry/)
37
+
38
+ This is the official Python client library for the [Ipregistry](https://ipregistry.co) IP geolocation and threat data API,
39
+ allowing you to lookup your own IP address or specified ones. Responses return multiple data points including carrier,
40
+ company, currency, location, timezone, threat information, and more.
41
+
42
+ Starting version 3 of the library, support for Python 2 has been dropped. Version 5 and above require Python 3.10+.
43
+
44
+ ## Getting Started
45
+
46
+ 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).
47
+
48
+ ### Installation
49
+
50
+ ```
51
+ pip install ipregistry
52
+ ```
53
+
54
+ ### Quick Start
55
+
56
+ #### Single IP Lookup
57
+
58
+ ```python
59
+ from ipregistry import IpregistryClient
60
+
61
+ client = IpregistryClient("YOUR_API_KEY")
62
+ response = client.lookup_ip("54.85.132.205")
63
+
64
+ # Printing whole response
65
+ print(response)
66
+
67
+ # Retrieving a specific field
68
+ country_code = response.data.location.country.code
69
+
70
+ # Getting number of credits consumed or remaining
71
+ credits_consumed = response.credits.consumed
72
+ credits_remaining = response.credits.remaining
73
+ ```
74
+
75
+ #### Single ASN Lookup
76
+
77
+ ```python
78
+ from ipregistry import IpregistryClient
79
+
80
+ client = IpregistryClient("YOUR_API_KEY")
81
+ response = client.lookup_asn(42)
82
+ print(response.credits.consumed)
83
+ print(response.data.prefixes)
84
+ print(response.data.relationships)
85
+ ```
86
+
87
+ #### Batch IP Lookup
88
+
89
+ ```python
90
+ from ipregistry import IpregistryClient
91
+
92
+ client = IpregistryClient("YOUR_API_KEY")
93
+ response = client.batch_lookup_ips(["54.85.132.205", "8.8.8.8", "2001:67c:2e8:22::c100:68b"])
94
+ for ip_info in response.data:
95
+ print(ip_info)
96
+ ```
97
+
98
+ #### Origin IP Lookup
99
+
100
+ ```python
101
+ from ipregistry import IpregistryClient
102
+
103
+ client = IpregistryClient("YOUR_API_KEY")
104
+ response = client.origin_lookup_ip()
105
+ print(response.data)
106
+ ```
107
+
108
+ #### User-Agent Parsing
109
+
110
+ ```python
111
+ from ipregistry import IpregistryClient
112
+
113
+ client = IpregistryClient("YOUR_API_KEY")
114
+ 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')
115
+ print(response.data)
116
+ ```
117
+
118
+ #### Asynchronous Client
119
+
120
+ An asyncio-based client with the same feature set is available when the library is installed
121
+ with the `async` extra (`pip install ipregistry[async]`):
122
+
123
+ ```python
124
+ from ipregistry import AsyncIpregistryClient
125
+
126
+ async def main():
127
+ async with AsyncIpregistryClient("YOUR_API_KEY") as client:
128
+ response = await client.lookup_ip("54.85.132.205")
129
+ print(response.data.location.country.code)
130
+ ```
131
+
132
+ More advanced examples are available in the [samples](https://github.com/ipregistry/ipregistry-python/tree/master/samples)
133
+ folder.
134
+
135
+ ### Configuration
136
+
137
+ Timeouts, retries and the User-Agent header are configurable through `IpregistryConfig`:
138
+
139
+ ```python
140
+ from ipregistry import IpregistryClient, IpregistryConfig
141
+
142
+ config = IpregistryConfig(
143
+ "YOUR_API_KEY",
144
+ timeout=15, # seconds; a (connect, read) tuple is also accepted
145
+ retry_max_attempts=3, # attempts per request, including the initial one
146
+ retry_interval=1, # base delay in seconds, doubled on each retry
147
+ retry_on_server_error=True, # retry 5xx responses
148
+ retry_on_too_many_requests=False, # retry 429 responses, honoring Retry-After
149
+ user_agent=None # custom User-Agent header value
150
+ )
151
+ client = IpregistryClient(config)
152
+ ```
153
+
154
+ Transient network errors are always retried up to `retry_max_attempts`.
155
+
156
+ The client reuses pooled HTTP connections through a `requests.Session`. You may pass your own
157
+ session with `IpregistryClient("YOUR_API_KEY", session=my_session)` for proxy or TLS control,
158
+ and release resources with `client.close()` or by using the client as a context manager.
159
+
160
+ Batch lookups larger than the API limit of 1024 items are automatically split into concurrent
161
+ chunks. Tune this with `IpregistryClient("YOUR_API_KEY", max_batch_size=1024, batch_concurrency=4)`.
162
+
163
+ ### Caching
164
+
165
+ This Ipregistry client library has built-in support for in-memory caching. By default caching is disabled.
166
+ Below are examples to enable and configure a caching strategy. Once enabled, default cache strategy is to memoize up to
167
+ 2048 lookups for at most 10min. You can change preferences as follows:
168
+
169
+ #### Enabling caching
170
+
171
+ Enable caching by passing an instance of `InMemoryCache`:
172
+
173
+ ```python
174
+ from ipregistry import InMemoryCache, IpregistryClient
175
+
176
+ client = IpregistryClient("YOUR_API_KEY", cache=InMemoryCache(maxsize=2048, ttl=600))
177
+ ```
178
+
179
+ #### Disabling caching
180
+
181
+ Disable caching by passing an instance of `NoCache`:
182
+
183
+ ```python
184
+ from ipregistry import IpregistryClient, NoCache
185
+
186
+ client = IpregistryClient("YOUR_API_KEY", cache=NoCache())
187
+ ```
188
+
189
+ ### European Union Base URL
190
+
191
+ Using the EU base URL, your requests are handled by the closest cluster of nodes in the European Union:
192
+
193
+ ```python
194
+ from ipregistry import IpregistryClient, NoCache
195
+
196
+ client = IpregistryClient(IpregistryConfig("YOUR_API_KEY").with_eu_base_url())
197
+ ```
198
+
199
+ ### Errors
200
+
201
+ All Ipregistry exceptions inherit `IpregistryError` class.
202
+
203
+ Main subtypes are `ApiError` and `ClientError`. Failed entries in batch responses are instances of `IpregistryLookupError` (also available under the legacy alias `LookupError`).
204
+
205
+ Errors of type _ApiError_ include a `code` field that maps to the one described in the [Ipregistry documentation](https://ipregistry.co/docs/errors), along with a typed `error_code` enum value (`ErrorCode`) that is `None` for unrecognized codes.
206
+
207
+ ### Filtering bots
208
+
209
+ You might want to prevent Ipregistry API requests for crawlers or bots browsing your pages.
210
+
211
+ A manner to proceed is to identify bots using the `User-Agent` header.
212
+ To ease this process, the library includes a utility method:
213
+
214
+ ```python
215
+ from ipregistry import UserAgents
216
+
217
+ is_bot = UserAgents.is_bot('YOUR_USER_AGENT_HEADER_VALUE_HERE')
218
+ ```
219
+
220
+ ## Other Libraries
221
+
222
+ There are official Ipregistry client libraries available for many languages including
223
+ [Java](https://github.com/ipregistry/ipregistry-java),
224
+ [Javascript](https://github.com/ipregistry/ipregistry-javascript), and more.
225
+
226
+ Are you looking for an official client with a programming language or framework we do not support yet?
227
+ [let us know](mailto:support@ipregistry.co).
@@ -0,0 +1,197 @@
1
+ [<img src="https://cdn.ipregistry.co/icons/favicon-96x96.png" alt="Ipregistry" width="64"/>](https://ipregistry.co/)
2
+ # Ipregistry Python Client Library
3
+
4
+ [![License](http://img.shields.io/:license-apache-blue.svg)](LICENSE)
5
+ [![Actions Status](https://github.com/ipregistry/ipregistry-python/workflows/Tests/badge.svg)](https://github.com/ipregistry/ipregistry-python/actions)
6
+ [![PyPI](https://img.shields.io/pypi/v/ipregistry)](https://pypi.org/project/ipregistry/)
7
+
8
+ This is the official Python client library for the [Ipregistry](https://ipregistry.co) IP geolocation and threat data API,
9
+ allowing you to lookup your own IP address or specified ones. Responses return multiple data points including carrier,
10
+ company, currency, location, timezone, threat information, and more.
11
+
12
+ Starting version 3 of the library, support for Python 2 has been dropped. Version 5 and above require Python 3.10+.
13
+
14
+ ## Getting Started
15
+
16
+ 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).
17
+
18
+ ### Installation
19
+
20
+ ```
21
+ pip install ipregistry
22
+ ```
23
+
24
+ ### Quick Start
25
+
26
+ #### Single IP Lookup
27
+
28
+ ```python
29
+ from ipregistry import IpregistryClient
30
+
31
+ client = IpregistryClient("YOUR_API_KEY")
32
+ response = client.lookup_ip("54.85.132.205")
33
+
34
+ # Printing whole response
35
+ print(response)
36
+
37
+ # Retrieving a specific field
38
+ country_code = response.data.location.country.code
39
+
40
+ # Getting number of credits consumed or remaining
41
+ credits_consumed = response.credits.consumed
42
+ credits_remaining = response.credits.remaining
43
+ ```
44
+
45
+ #### Single ASN Lookup
46
+
47
+ ```python
48
+ from ipregistry import IpregistryClient
49
+
50
+ client = IpregistryClient("YOUR_API_KEY")
51
+ response = client.lookup_asn(42)
52
+ print(response.credits.consumed)
53
+ print(response.data.prefixes)
54
+ print(response.data.relationships)
55
+ ```
56
+
57
+ #### Batch IP Lookup
58
+
59
+ ```python
60
+ from ipregistry import IpregistryClient
61
+
62
+ client = IpregistryClient("YOUR_API_KEY")
63
+ response = client.batch_lookup_ips(["54.85.132.205", "8.8.8.8", "2001:67c:2e8:22::c100:68b"])
64
+ for ip_info in response.data:
65
+ print(ip_info)
66
+ ```
67
+
68
+ #### Origin IP Lookup
69
+
70
+ ```python
71
+ from ipregistry import IpregistryClient
72
+
73
+ client = IpregistryClient("YOUR_API_KEY")
74
+ response = client.origin_lookup_ip()
75
+ print(response.data)
76
+ ```
77
+
78
+ #### User-Agent Parsing
79
+
80
+ ```python
81
+ from ipregistry import IpregistryClient
82
+
83
+ client = IpregistryClient("YOUR_API_KEY")
84
+ 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')
85
+ print(response.data)
86
+ ```
87
+
88
+ #### Asynchronous Client
89
+
90
+ An asyncio-based client with the same feature set is available when the library is installed
91
+ with the `async` extra (`pip install ipregistry[async]`):
92
+
93
+ ```python
94
+ from ipregistry import AsyncIpregistryClient
95
+
96
+ async def main():
97
+ async with AsyncIpregistryClient("YOUR_API_KEY") as client:
98
+ response = await client.lookup_ip("54.85.132.205")
99
+ print(response.data.location.country.code)
100
+ ```
101
+
102
+ More advanced examples are available in the [samples](https://github.com/ipregistry/ipregistry-python/tree/master/samples)
103
+ folder.
104
+
105
+ ### Configuration
106
+
107
+ Timeouts, retries and the User-Agent header are configurable through `IpregistryConfig`:
108
+
109
+ ```python
110
+ from ipregistry import IpregistryClient, IpregistryConfig
111
+
112
+ config = IpregistryConfig(
113
+ "YOUR_API_KEY",
114
+ timeout=15, # seconds; a (connect, read) tuple is also accepted
115
+ retry_max_attempts=3, # attempts per request, including the initial one
116
+ retry_interval=1, # base delay in seconds, doubled on each retry
117
+ retry_on_server_error=True, # retry 5xx responses
118
+ retry_on_too_many_requests=False, # retry 429 responses, honoring Retry-After
119
+ user_agent=None # custom User-Agent header value
120
+ )
121
+ client = IpregistryClient(config)
122
+ ```
123
+
124
+ Transient network errors are always retried up to `retry_max_attempts`.
125
+
126
+ The client reuses pooled HTTP connections through a `requests.Session`. You may pass your own
127
+ session with `IpregistryClient("YOUR_API_KEY", session=my_session)` for proxy or TLS control,
128
+ and release resources with `client.close()` or by using the client as a context manager.
129
+
130
+ Batch lookups larger than the API limit of 1024 items are automatically split into concurrent
131
+ chunks. Tune this with `IpregistryClient("YOUR_API_KEY", max_batch_size=1024, batch_concurrency=4)`.
132
+
133
+ ### Caching
134
+
135
+ This Ipregistry client library has built-in support for in-memory caching. By default caching is disabled.
136
+ Below are examples to enable and configure a caching strategy. Once enabled, default cache strategy is to memoize up to
137
+ 2048 lookups for at most 10min. You can change preferences as follows:
138
+
139
+ #### Enabling caching
140
+
141
+ Enable caching by passing an instance of `InMemoryCache`:
142
+
143
+ ```python
144
+ from ipregistry import InMemoryCache, IpregistryClient
145
+
146
+ client = IpregistryClient("YOUR_API_KEY", cache=InMemoryCache(maxsize=2048, ttl=600))
147
+ ```
148
+
149
+ #### Disabling caching
150
+
151
+ Disable caching by passing an instance of `NoCache`:
152
+
153
+ ```python
154
+ from ipregistry import IpregistryClient, NoCache
155
+
156
+ client = IpregistryClient("YOUR_API_KEY", cache=NoCache())
157
+ ```
158
+
159
+ ### European Union Base URL
160
+
161
+ Using the EU base URL, your requests are handled by the closest cluster of nodes in the European Union:
162
+
163
+ ```python
164
+ from ipregistry import IpregistryClient, NoCache
165
+
166
+ client = IpregistryClient(IpregistryConfig("YOUR_API_KEY").with_eu_base_url())
167
+ ```
168
+
169
+ ### Errors
170
+
171
+ All Ipregistry exceptions inherit `IpregistryError` class.
172
+
173
+ Main subtypes are `ApiError` and `ClientError`. Failed entries in batch responses are instances of `IpregistryLookupError` (also available under the legacy alias `LookupError`).
174
+
175
+ Errors of type _ApiError_ include a `code` field that maps to the one described in the [Ipregistry documentation](https://ipregistry.co/docs/errors), along with a typed `error_code` enum value (`ErrorCode`) that is `None` for unrecognized codes.
176
+
177
+ ### Filtering bots
178
+
179
+ You might want to prevent Ipregistry API requests for crawlers or bots browsing your pages.
180
+
181
+ A manner to proceed is to identify bots using the `User-Agent` header.
182
+ To ease this process, the library includes a utility method:
183
+
184
+ ```python
185
+ from ipregistry import UserAgents
186
+
187
+ is_bot = UserAgents.is_bot('YOUR_USER_AGENT_HEADER_VALUE_HERE')
188
+ ```
189
+
190
+ ## Other Libraries
191
+
192
+ There are official Ipregistry client libraries available for many languages including
193
+ [Java](https://github.com/ipregistry/ipregistry-java),
194
+ [Javascript](https://github.com/ipregistry/ipregistry-javascript), and more.
195
+
196
+ Are you looking for an official client with a programming language or framework we do not support yet?
197
+ [let us know](mailto:support@ipregistry.co).
@@ -0,0 +1,8 @@
1
+ from .async_client import AsyncDefaultRequestHandler as AsyncDefaultRequestHandler
2
+ from .async_client import AsyncIpregistryClient as AsyncIpregistryClient
3
+ from .cache import *
4
+ from .core import *
5
+ from .json import *
6
+ from .model import *
7
+ from .request import *
8
+ from .util import *