corehttp.transport.httpx package

class corehttp.transport.httpx.AsyncHttpXTransport(*, client: AsyncClient | None = None, client_owner: bool = True, use_env_settings: bool = True, **kwargs: Any)[source]

Implements a basic async httpx HTTP sender

Keyword Arguments:
  • client (httpx.AsyncClient) – HTTPX client to use instead of the default one

  • client_owner (bool) – Decide if the client provided by user is owned by this transport. Default to True.

  • use_env_settings (bool) – Uses proxy settings from environment. Defaults to True.

async close() None[source]

Close the session if it is not externally owned.

async open() None[source]

Assign new session if one does not already exist.

async send(request: HttpRequest, *, stream: bool = False, **kwargs) AsyncHttpResponse[source]

Send the request using this HTTP sender.

Parameters:

request (HttpRequest) – The request object to be sent.

Keyword Arguments:

stream (bool) – Whether to stream the response. Defaults to False.

Returns:

The response object.

Return type:

AsyncHttpResponse

async sleep(duration: float) None

Sleep for the specified duration.

You should always ask the transport to sleep, and not call directly the stdlib. This is mostly important in async, as the transport may not use asyncio but other implementation like trio and they their own way to sleep, but to keep design consistent, it’s cleaner to always ask the transport to sleep and let the transport implementor decide how to do it. By default, this method will use “asyncio”, and don’t need to be overridden if your transport does too.

Parameters:

duration (float) – The number of seconds to sleep.

class corehttp.transport.httpx.HttpXTransport(*, client: Client | None = None, client_owner: bool = True, use_env_settings: bool = True, **kwargs: Any)[source]

Implements a basic httpx HTTP sender

Keyword Arguments:
  • client (httpx.Client) – HTTPX client to use instead of the default one

  • client_owner (bool) – Decide if the client provided by user is owned by this transport. Default to True.

  • use_env_settings (bool) – Uses proxy settings from environment. Defaults to True.

close() None[source]

Close the session.

Returns:

None

Return type:

None

open() None[source]

Assign new session if one does not already exist.

send(request: HttpRequest, *, stream: bool = False, **kwargs) HttpResponse[source]

Send a request and get back a response.

Parameters:

request (HTTPRequest) – The request object to be sent.

Keyword Arguments:

stream (bool) – Whether to stream the response. Defaults to False.

Returns:

An HTTPResponse object.

Return type:

HttpResponse

sleep(duration: float) None

Sleep for the specified duration.

You should always ask the transport to sleep, and not call directly the stdlib. This is mostly important in async, as the transport may not use asyncio but other implementations like trio and they have their own way to sleep, but to keep design consistent, it’s cleaner to always ask the transport to sleep and let the transport implementor decide how to do it.

Parameters:

duration (float) – The number of seconds to sleep.