GitHub

httpx_client

API reference for httpx_client.

An HttpClient backed by httpx (the pyfect-dev[httpx] extra).

layer provides the client; layer_with(**options) passes options to httpx.AsyncClient (verify, proxy, limits, ...). The httpx client runs on an asyncio loop of its own, on a background thread, so the layer works under run_blocking and run_async alike, and closes with the layer::

program.pipe(fx.provide(httpx_client.layer))

Interrupting a request cancels it in httpx (closing its connection); response bodies stream chunk by chunk, and a request body Stream is pulled as httpx sends it. httpx applies no timeout by default here, as fetch applies none: use Effect.timeout.

Values

AttributeTypeDescription
layerLayer[HttpClient]

An HttpClient on httpx with its default options (and no timeout).

Functions

make

make(**options) -> Effect[HttpClientService[HttpClientError], Never, Scope]

A client on a new httpx.AsyncClient(**options), closed with the scope.

The request defaults (headers, params, cookies, auth) are added to each request by the pyfect client, not by httpx, so follow_redirects drops their credentials on a hop to another origin as it does a request's own. auth is a (username, password) pair and cookies a mapping; set any other credential per request.

ParameterTypeDescription
optionsAny = {}

Returns Effect[HttpClientService[HttpClientError], Never, Scope]

def make(**options: Any) -> Effect[HttpClientService[HttpClientError], Never, Scope]:
    """A client on a new ``httpx.AsyncClient(**options)``, closed with the
    scope.

    The request defaults (``headers``, ``params``, ``cookies``, ``auth``)
    are added to each request by the pyfect client, not by httpx, so
    ``follow_redirects`` drops their credentials on a hop to another origin
    as it does a request's own. ``auth`` is a ``(username, password)`` pair
    and ``cookies`` a mapping; set any other credential per request."""
    defaults, transport = split_options(options)
    backend = acquire_release(
        sync(lambda: _Backend(dict(transport))), lambda backend, _exit: backend.close()
    )
    return backend.map(lambda backend: _with_defaults(make_client(backend.send), defaults))

layer_with

layer_with(**options) -> Layer[HttpClient]

layer with options for httpx.AsyncClient (see make).

ParameterTypeDescription
optionsAny = {}

Returns Layer[HttpClient]

def layer_with(**options: Any) -> Layer[HttpClient]:
    """``layer`` with options for ``httpx.AsyncClient`` (see ``make``)."""
    split_options(options)
    return layer_effect(HttpClient, make(**options))