Skip to content

The client

volumes.Client(...)

client = volumes.Client(
    api_key=None,  # default: the VOLUMES_API_KEY environment variable
    base_url=None,  # default: the VOLUMES_BASE_URL environment variable
    timeout=30.0,  # seconds per request (or an httpx.Timeout); None for no timeout
    max_retries=2,  # retries after the first attempt, 0 to 10; 0 disables retrying
    http_client=None,  # an httpx.Client of your own (proxies, custom transports, tests)
)

Every argument is keyword-only: write volumes.Client(api_key=...), not volumes.Client("...").

Both the API key and the base URL are required. If either is missing from the arguments and from the environment, volumes.ConfigurationError is raised immediately, before any request.

The base URL must be an https:// URL, because the API key travels in a request header. Plain http:// is accepted only for a loopback address, which is what a server on your own machine has during development:

  • localhost, in any letter case;
  • an IPv4 address in 127.0.0.0/8, written as four decimal numbers (127.0.0.1);
  • the IPv6 loopback address in brackets, [::1]. Other ways of writing that same address, such as [0:0:0:0:0:0:0:1], are accepted too.

For any other host it is a ConfigurationError, and so are other ways of writing an address that may reach your own machine (127.1, [::ffff:127.0.0.1], a trailing dot).

The URL may include a port from 1 to 65535, written in plain decimal without leading zeros (a colon after the host has to be followed by one), and a path prefix (https://gateway.example.test:8443/volumes). It may not contain credentials, spaces, control characters or backslashes, and no ? or #, not even one with nothing after it. A % has to begin a percent-escape such as %20; write a literal percent sign as %25. The URL may be at most 2048 characters long. Whitespace before or after the whole value is ignored.

The host and the port have to be written in ASCII, and the host has to be an IP address or a host name within the limits of the DNS: labels of 1 to 63 characters separated by single dots, at most 253 characters in all (one trailing dot is allowed). An IPv4 address is four decimal numbers without leading zeros. An internationalised host name is written in its punycode form (https://xn--caf-dma.example.test, not the name with the accented letter), and every label that starts with xn-- has to be valid punycode. The reason is that URL parsers do not agree on what to do with other characters in a host, a full-width digit or an ideographic full stop for instance, and the same text must not name one host under one version of the HTTP library and another host under the next. A path prefix may contain other characters.

An unusable base URL is always a ConfigurationError, raised when the client is created, and the decision does not depend on the installed httpx version.

timeout is a finite number of seconds, greater than zero and at most 86400 (one day), or an httpx.Timeout made of such numbers. To run without a timeout pass timeout=None; float("inf"), NaN and larger numbers are rejected with ConfigurationError when the client is created.

A client holds a connection pool. Reuse one client for many calls, and close it when you are done, either with client.close() or by using it as a context manager (with volumes.Client() as client:). A closed client raises volumes.ClientClosedError if it is used again, including when it (or the http_client you gave it) is closed while a call is waiting between retries. If you pass your own http_client, it stays yours: the SDK does not close it.

Configuration

Setting Argument Environment variable Default
API key api_key VOLUMES_API_KEY none (required)
API endpoint base_url VOLUMES_BASE_URL none (required)
Request timeout timeout 30.0 seconds (None = no timeout)
Retries max_retries 2
HTTP client http_client a new httpx.Client

An argument always wins over the environment variable.

There is no default endpoint: use the URL you were given. It has to be an https:// URL, because the API key travels in a request header; http:// is accepted only for a loopback address, for local development (see volumes.Client(...)).

The client identifies itself with User-Agent: volumes-python/<version> and sends nothing else about your environment. Redirects are not followed.

Proxies

The HTTP client the SDK creates for itself follows the usual proxy settings of the environment (HTTPS_PROXY, ALL_PROXY, NO_PROXY, ...) for an https:// endpoint, as httpx does: such a request is tunnelled through the proxy, encrypted end to end.

For a plain http:// endpoint, which can only be a loopback address, it ignores them and always connects directly. A plain-http request sent through a proxy is not tunnelled: the proxy would receive the whole request, API key included, in clear, and a request to your own machine has no business going to another one.

Proxy or TLS settings in the environment that cannot be used are reported in one of two ways, and which one depends partly on the installed httpx:

  • What httpx notices when a client is created makes creating a client for an https:// endpoint raise ConfigurationError. On every supported httpx version that covers a proxy URL with a scheme httpx does not support and a SOCKS proxy without the package for it. Newer versions notice more at that point (some malformed proxy URLs, a certificate file that does not exist).
  • Everything else shows up at the first request as APIConnectionError: a proxy that cannot be reached, a proxy URL that names no usable host. (Older httpx versions ignore a certificate file that does not exist.)

Either way the exception is a VolumesError.

This applies to the SDK's own HTTP client only. If you pass your own http_client, how it routes requests is yours to decide and the SDK does not change it: a client created with httpx.Client() reads the environment, so with it a plain-http request does go to a proxy named there. Create it with httpx.Client(trust_env=False) if that is not what you want.