AioHttpTransport Class

AioHttp HTTP sender implementation.

Fully asynchronous implementation using the aiohttp library.

Environment variables (read when use_env_settings is True, the default):

  • HTTP_PROXY - Proxy URL for HTTP requests.

  • HTTPS_PROXY - Proxy URL for HTTPS requests.

  • NO_PROXY - Comma-separated list of hosts that should bypass the proxy.

Constructor

AioHttpTransport(*, session: ClientSession | None = None, loop=None, session_owner: bool = True, **kwargs)

Keyword-Only Parameters

Name Description
session
<xref:aiohttp.ClientSession>

The client session.

Default value: None
session_owner

Session owner. Defaults True.

Default value: True
use_env_settings

Uses proxy settings from environment. Defaults to True.

loop
Default value: None

Examples

Asynchronous transport with aiohttp.


   from azure.core.pipeline.transport import AioHttpTransport

   async with AsyncPipeline(AioHttpTransport(), policies=policies) as pipeline:
       response = await pipeline.run(request)

Methods

close

Closes the connection.

open

Opens the connection.

send

Send the request using this HTTP sender.

Will pre-load the body into memory to be available with a sync method. Pass stream=True to avoid this behavior.

sleep

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.

close

Closes the connection.

async close()

open

Opens the connection.

async open()

send

Send the request using this HTTP sender.

Will pre-load the body into memory to be available with a sync method. Pass stream=True to avoid this behavior.

async send(request: HttpRequest, *, stream: bool = False, proxies: MutableMapping[str, str] | None = None, **config: Any) -> AsyncHttpResponse

Parameters

Name Description
request
Required

The HttpRequest object

Keyword-Only Parameters

Name Description
stream

Defaults to False.

Default value: False
proxies

dict of proxy to used based on protocol. Proxy is a dict (protocol, url)

Default value: None

Returns

Type Description

The AsyncHttpResponse

sleep

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.

async sleep(duration: float) -> None

Parameters

Name Description
duration
Required

The number of seconds to sleep.