Skip to content

Commit d2335fb

Browse files
Document new features in README and changelog
1 parent ffc045e commit d2335fb

2 files changed

Lines changed: 66 additions & 3 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,31 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

88
## [Unreleased]
9+
### Added
10+
- Add an asyncio-based `AsyncIpregistryClient` with the same feature set, available with the `async`
11+
extra: `pip install ipregistry[async]`.
12+
- Add configurable retries through `IpregistryConfig`: `retry_max_attempts`, `retry_interval`,
13+
`retry_on_server_error` and `retry_on_too_many_requests` (honoring the `Retry-After` header).
14+
Transient network errors are now retried too.
15+
- Add a typed `ErrorCode` enum exposed as `ApiError.error_code`.
16+
- Add automatic splitting of batch lookups larger than the API limit of 1024 items into concurrent
17+
chunks, tunable with the `max_batch_size` and `batch_concurrency` client options.
18+
- Add `close()` and context manager support to `IpregistryClient`, plus an optional `session`
19+
option to provide a custom `requests.Session`.
20+
- Add a `user_agent` configuration option to customize the User-Agent header.
21+
- Add a release workflow publishing to PyPI through trusted publishing, a ruff lint workflow, and
22+
a weekly scheduled workflow running tests against the live API.
923
### Changed
1024
- Require Python 3.10+.
11-
- Update all dependencies to their latest versions.
25+
- Update all dependencies to their latest versions and remove the dependency on tenacity.
26+
- Reuse pooled HTTP connections through a `requests.Session` instead of opening a new connection
27+
per request.
28+
- Align the default request timeout with other Ipregistry client libraries: 15 seconds instead of 5.
29+
- Origin lookups are no longer cached: cached requester data would be stale or wrong when the
30+
network context changes.
31+
- Cache keys are now deterministic regardless of the order lookup options are given in.
1232
- Remove the redundant retry on `origin_lookup_ip` that could triple retry attempts.
33+
- Detect the Yahoo Slurp crawler in `UserAgents.is_bot`.
1334
### Fixed
1435
- Fix nested model fields (`Connection`, `CurrencyFormat`, `UserAgent` device/engine/os, `RequesterIpInfo` user_agent)
1536
raising a validation error when excluded from a response using the `fields` parameter.

‎README.md‎

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ This is the official Python client library for the [Ipregistry](https://ipregist
99
allowing you to lookup your own IP address or specified ones. Responses return multiple data points including carrier,
1010
company, currency, location, timezone, threat information, and more.
1111

12-
Starting version 3 of the library, support for Python 2 has been dropped and the library requires Python 3.6+.
12+
Starting version 3 of the library, support for Python 2 has been dropped. Version 5 and above require Python 3.10+.
1313

1414
## Getting Started
1515

@@ -85,9 +85,51 @@ response = client.parse_user_agent('Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/
8585
print(response.data)
8686
```
8787

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

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+
91133
### Caching
92134

93135
This Ipregistry client library has built-in support for in-memory caching. By default caching is disabled.
@@ -130,7 +172,7 @@ All Ipregistry exceptions inherit `IpregistryError` class.
130172

131173
Main subtypes are `ApiError` and `ClientError`.
132174

133-
Errors of type _ApiError_ include a code field that maps to the one described in the [Ipregistry documentation](https://ipregistry.co/docs/errors).
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.
134176

135177
### Filtering bots
136178

0 commit comments

Comments
 (0)