from ucall import Response, Completed, Client1.0.0-rc.1 · 60202332
A Client submits calls without driving the network, and polls to drive them and collect what finished.
It holds up to connections connections, reusing them across calls, and carries up to pipelined_calls calls on each.
submit(verb, url, body, headers, security=..., noise_peer_key=..., context=...) borrows its URL, header lines, body and key until the call completes, and tags it with any context object.
A call admitted once completes exactly once, and a client already holding calls unretrieved calls refuses more with ucall.Error and Status.CONTENDED; calls defaults to connections times pipelined_calls. take_completed(timeout_microseconds, capacity) drives every admitted call and returns up to capacity finished ones as Completed objects, waiting up to its timeout for the first, and a zero timeout performs one nonblocking round.
A Completed carries the context, the final status, a message on failure, and the response, None on failure.
request, get, post, put, delete and patch submit one call and poll until it finishes, keeping the completions of other calls they retrieve meanwhile for the next take_completed, which hands those out first.
They take json= to send a value as JSON with its content type, and raise ucall.Error when the exchange fails.
Every calling method also takes this call’s timeout_microseconds=, max_retries= and max_redirects= in place of the client’s, and a noise_private_key= private key in place of its own.
A Client takes log=, log_level= and log_format= as a server does, reporting dials that fail every address, refused handshakes and refused redirects. max_response_bytes= caps the response a call buffers, failing the call with Status.OVERFLOW past it, and zero takes the largest receive buffer the kernel grants a socket.
Host names resolve through the library’s own stub resolver, never blocking the calling thread on the system’s, and connections race the answered addresses as Happy Eyeballs does.
Every received response is a Response, whatever its HTTP status, and only a failed exchange is an error; fields() lists its header fields in arrival order as a request’s does.
A Response owns its received bytes, so it stays readable after its Client is gone, and supports the buffer protocol as a request does: bytes(response) copies its body and response.body views it.
Releasing the client cancels the calls still in flight and discards completions not yet retrieved.
API
ClassResponseOne received HTTP response, which owns its bytes and outlives its client.4