Client¶
AlmaClient is the entry point. It is a plain async class – no framework
dependency – composing a niquests.AsyncSession for transport, a TokenBucket
for rate limiting, an AdaptiveController for backpressure, and an
asyncio.Semaphore to cap concurrency.
Use it as an async context manager so the underlying session is closed:
Most of what you will use it for is the namespaces it exposes – client.users,
client.bibs, client.acq, client.config, client.analytics, client.primo
– each documented on its own page.
AlmaClient
¶
AlmaClient(
apikey: str,
location: Literal[
"America",
"Europe",
"Asia Pacific",
"Canada",
"China",
] = "Europe",
*,
rate_limit: float = 25.0,
concurrent_requests: int = 150,
retry_attempts: int = 3,
backoff_factor: float = 0.5,
recovery_increment: float = 1.0,
recovery_window: float = 10.0,
cooldown: float = 5.0,
max_wait: float | None = None,
client: AsyncSession | None = None,
)
Async API wrapper for the Alma library management system.
Composed of: niquests.AsyncSession (transport), TokenBucket (rate limiting), AdaptiveController (AIMD backpressure), asyncio.Semaphore (concurrency cap).
execute
async
¶
Send one request through the rate limiter, retry loop and error mapping.
You are not normally expected to call this. Every namespace method –
client.users.get_user(), client.bibs.get_item() and the rest – is a
thin wrapper around it that supplies the URL, the parser and the response
type. Prefer those: they are typed, and they name the thing you are asking
for. This is the shared chokepoint they all funnel through, and it is public
so that the two cases below remain possible.
Call it directly when:
- Alma exposes an endpoint almapy does not wrap yet. Going through
executekeeps the throttling, retries, backpressure and error mapping that raw HTTP would lose. - You need to override the retry policy for a single request, with
retry=. The namespace methods do not accept that argument.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
str
|
HTTP verb, e.g. |
required |
url
|
str
|
Path relative to the regional gateway's |
required |
parser
|
Parser
|
How to decode the response body – |
required |
model
|
Any
|
Optional Pydantic model class to validate the response into, exactly as on the namespace methods. |
None
|
validate
|
Callable[[Response], None]
|
Response validator, run on every response. Defaults to the one
mapping Alma's error codes onto |
_validate_response
|
retry
|
bool | None
|
|
None
|
**kwargs
|
Any
|
Passed to the underlying |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
The parsed body: a |
Any
|
|
Raises:
| Type | Description |
|---|---|
APIClientError
|
For 4xx responses, or a more specific subclass where Alma's error code maps to one. |
APIServerError
|
For 5xx responses that survived the retries. |
MalformedResponseError
|
For a 2xx whose body could not be parsed as the requested format – an HTML maintenance page, say. |
ThrottleTimeoutError
|
If |
Examples:
Reaching an endpoint almapy does not wrap: