Skip to content

Custom transport

Pass your own httpx.Client to control proxies, TLS settings or connection limits. The SDK still adds its own headers, your API key and its timeout to every request it sends, without changing your client's settings (see Proxies for what that means for a plain http:// endpoint).

import httpx
import volumes

http_client = httpx.Client(limits=httpx.Limits(max_connections=4))
client = volumes.Client(http_client=http_client)

What the SDK does with what your client raises:

Raised inside your http_client You get
httpx.TimeoutException APITimeoutError (retried)
any other httpx.TransportError APIConnectionError (retried)
httpx.HTTPStatusError, for example from a response hook that calls raise_for_status() the same exception as without the hook, chosen by the status (AuthenticationError, CaptureNotFoundError, ServerError, ...) and retried or not by the same rules. If the hook did not read the body first, the body is gone: code is then None and a 404 is a plain NotFoundError.
any other httpx.HTTPError APIConnectionError (not retried)
httpx.InvalidURL InvalidArgumentError
the client being closed ClientClosedError
anything else: an exception of your own transport, hook or auth code that exception, unchanged

This is also how to test code that uses the SDK without any network:

import httpx
import volumes


def handler(request: httpx.Request) -> httpx.Response:
    return httpx.Response(
        200, json={"captures": [{"capture_id": "capture_demo_001"}], "next_cursor": None}
    )


client = volumes.Client(
    api_key="test-key",
    base_url="https://api.example.test",
    http_client=httpx.Client(transport=httpx.MockTransport(handler)),
)
assert client.list_captures() == [volumes.Capture("capture_demo_001")]