azure.core.pipeline.transport¶
-
class
azure.core.pipeline.transport.
AioHttpTransport
(*, session: Optional[aiohttp.client.ClientSession] = None, loop=None, session_owner=True, **kwargs)[source]¶ AioHttp HTTP sender implementation.
Fully asynchronous implementation using the aiohttp library.
- Parameters
session – The client session.
session_owner (bool) – Session owner. Defaults True.
- Keyword Arguments
use_env_settings (bool) – Uses proxy settings from environment. Defaults to True.
Example:
from azure.core.pipeline.transport import AioHttpTransport async with AsyncPipeline(AioHttpTransport(), policies=policies) as pipeline: response = await pipeline.run(request)
-
async
send
(request: azure.core.pipeline.transport._base.HttpRequest, **config: Any) → Optional[azure.core.pipeline.transport._base_async.AsyncHttpResponse][source]¶ -
async
send
(request: RestHttpRequest, **config: Any) → Optional[RestAsyncHttpResponse] 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.
- Parameters
request (HttpRequest) – The HttpRequest object
config – Any keyword arguments
- Returns
The AsyncHttpResponse
- Return type
- Keyword Arguments
-
async
sleep
(duration)¶
-
class
azure.core.pipeline.transport.
AioHttpTransportResponse
(request: azure.core.pipeline.transport._base.HttpRequest, aiohttp_response: aiohttp.client_reqrep.ClientResponse, block_size=None, *, decompress=True)[source]¶ Methods for accessing response body data.
- Parameters
request (HttpRequest) – The HttpRequest object
aiohttp_response (aiohttp.ClientResponse object) – Returned from ClientSession.request().
block_size (int) – block size of data sent over connection.
decompress (bool) – If True which is default, will attempt to decode the body based on the content-encoding header.
-
async
load_body
() → None[source]¶ Load in memory the body, so it could be accessible from sync methods.
-
parts
() → collections.abc.AsyncIterator¶ Assuming the content-type is multipart/mixed, will return the parts as an async iterator.
- Return type
AsyncIterator
- Raises
ValueError – If the content is not multipart/mixed
-
raise_for_status
()¶ Raises an HttpResponseError if the response has an error status code. If response is good, does nothing.
-
stream_download
(pipeline, **kwargs) → AsyncIterator[bytes][source]¶ Generator for streaming response body data.
- Parameters
pipeline (azure.core.pipeline.Pipeline) – The pipeline object
- Keyword Arguments
decompress (bool) – If True which is default, will attempt to decode the body based on the content-encoding header.
-
class
azure.core.pipeline.transport.
AsyncHttpResponse
(request: azure.core.pipeline.transport._base.HttpRequest, internal_response: Any, block_size: Optional[int] = None)[source]¶ An AsyncHttpResponse ABC.
Allows for the asynchronous streaming of data from the response.
-
parts
() → collections.abc.AsyncIterator[source]¶ Assuming the content-type is multipart/mixed, will return the parts as an async iterator.
- Return type
AsyncIterator
- Raises
ValueError – If the content is not multipart/mixed
-
raise_for_status
()¶ Raises an HttpResponseError if the response has an error status code. If response is good, does nothing.
-
stream_download
(pipeline, **kwargs) → AsyncIterator[bytes][source]¶ Generator for streaming response body data.
Should be implemented by sub-classes if streaming download is supported. Will return an asynchronous generator.
- Parameters
pipeline (azure.core.pipeline.Pipeline) – The pipeline object
- Keyword Arguments
decompress (bool) – If True which is default, will attempt to decode the body based on the content-encoding header.
-
-
class
azure.core.pipeline.transport.
AsyncioRequestsTransport
(**kwargs: Any)[source]¶ Identical implementation as the synchronous RequestsTransport wrapped in a class with asynchronous methods. Uses the built-in asyncio event loop.
Example:
from azure.core.pipeline.transport import AsyncioRequestsTransport async with AsyncPipeline(AsyncioRequestsTransport(), policies=policies) as pipeline: response = await pipeline.run(request)
-
close
()¶ Close the session if it is not externally owned.
-
open
()¶ Assign new session if one does not already exist.
-
async
send
(request: azure.core.pipeline.transport._base.HttpRequest, **kwargs: Any) → azure.core.pipeline.transport._base_async.AsyncHttpResponse[source]¶ -
async
send
(request: RestHttpRequest, **kwargs: Any) → RestAsyncHttpResponse Send the request using this HTTP sender.
- Parameters
request (HttpRequest) – The HttpRequest
- Returns
The AsyncHttpResponse
- Return type
- Keyword Arguments
session (requests.Session) – will override the driver session and use yours. Should NOT be done unless really required. Anything else is sent straight to requests.
proxies (dict) – will define the proxy to use. Proxy is a dict (protocol, url)
-
-
class
azure.core.pipeline.transport.
AsyncioRequestsTransportResponse
(request, requests_response, block_size=None)[source]¶ Asynchronous streaming of data from the response.
-
body
()¶ Return the whole body as bytes in memory.
-
parts
() → collections.abc.AsyncIterator¶ Assuming the content-type is multipart/mixed, will return the parts as an async iterator.
- Return type
AsyncIterator
- Raises
ValueError – If the content is not multipart/mixed
-
raise_for_status
()¶ Raises an HttpResponseError if the response has an error status code. If response is good, does nothing.
-
-
class
azure.core.pipeline.transport.
HttpRequest
(method: str, url: str, headers: Optional[Mapping[str, str]] = None, files: Optional[Any] = None, data: Optional[Any] = None)[source]¶ Represents a HTTP request.
URL can be given without query parameters, to be added later using “format_parameters”.
- Parameters
-
format_parameters
(params: Dict[str, str]) → None[source]¶ Format parameters into a valid query string. It’s assumed all parameters have already been quoted as valid URL strings.
- Parameters
params (dict) – A dictionary of parameters.
-
prepare_multipart_body
(content_index: int = 0) → int[source]¶ Will prepare the body of this request according to the multipart information.
This call assumes the on_request policies have been applied already in their correct context (sync/async)
Does nothing if “set_multipart_mixed” was never called.
-
set_bytes_body
(data)[source]¶ Set generic bytes as the body of the request.
Will set content-length.
- Parameters
data (bytes) – The request field data.
-
set_formdata_body
(data=None)[source]¶ Set form-encoded data as the body of the request.
- Parameters
data (dict) – The request field data.
-
set_json_body
(data)[source]¶ Set a JSON-friendly object as the body of the request.
- Parameters
data – A JSON serializable object
-
set_multipart_mixed
(*requests: azure.core.pipeline.transport._base.HttpRequest, **kwargs: Any) → None[source]¶ Set the part of a multipart/mixed.
Only supported args for now are HttpRequest objects.
boundary is optional, and one will be generated if you don’t provide one. Note that no verification are made on the boundary, this is considered advanced enough so you know how to respect RFC1341 7.2.1 and provide a correct boundary.
Any additional kwargs will be passed into the pipeline context for per-request policy configuration.
- Keyword Arguments
policies (list[SansIOHTTPPolicy]) – SansIOPolicy to apply at preparation time
boundary (str) – Optional boundary
- Parameters
requests – HttpRequests object
-
set_streamed_data_body
(data)[source]¶ Set a streamable data body.
- Parameters
data (stream or generator or asyncgenerator) – The request field data.
-
set_text_body
(data)[source]¶ Set a text as body of the request.
- Parameters
data (str) – A text to send as body.
-
class
azure.core.pipeline.transport.
HttpResponse
(request: azure.core.pipeline.transport._base.HttpRequest, internal_response: Any, block_size: Optional[int] = None)[source]¶ -
-
parts
() → Iterator[azure.core.pipeline.transport._base.HttpResponse][source]¶ Assuming the content-type is multipart/mixed, will return the parts as an iterator.
- Return type
iterator[HttpResponse]
- Raises
ValueError – If the content is not multipart/mixed
-
raise_for_status
()¶ Raises an HttpResponseError if the response has an error status code. If response is good, does nothing.
-
-
class
azure.core.pipeline.transport.
HttpTransport
(*args, **kwds)[source]¶ An http sender ABC.
-
class
azure.core.pipeline.transport.
RequestsTransport
(**kwargs: Any)[source]¶ Implements a basic requests HTTP sender.
Since requests team recommends to use one session per requests, you should not consider this class as thread-safe, since it will use one Session per instance.
In this simple implementation: - You provide the configured session if you want to, or a basic session is created. - All kwargs received by “send” are sent to session.request directly
- Keyword Arguments
session (requests.Session) – Request session to use instead of the default one.
session_owner (bool) – Decide if the session provided by user is owned by this transport. Default to True.
use_env_settings (bool) – Uses proxy settings from environment. Defaults to True.
Example:
from azure.core.pipeline.transport import RequestsTransport with Pipeline(transport=RequestsTransport(), policies=policies) as pipeline: response = pipeline.run(request)
-
send
(request, **kwargs)[source]¶ -
send
(request, **kwargs) Send request object according to configuration.
- Parameters
request (HttpRequest) – The request object to be sent.
- Returns
An HTTPResponse object.
- Return type
- Keyword Arguments
session (requests.Session) – will override the driver session and use yours. Should NOT be done unless really required. Anything else is sent straight to requests.
proxies (dict) – will define the proxy to use. Proxy is a dict (protocol, url)
-
sleep
(duration)¶
-
class
azure.core.pipeline.transport.
RequestsTransportResponse
(request, requests_response, block_size=None)[source]¶ Streaming of data from the response.
-
body
()¶ Return the whole body as bytes in memory.
-
parts
() → Iterator[azure.core.pipeline.transport._base.HttpResponse]¶ Assuming the content-type is multipart/mixed, will return the parts as an iterator.
- Return type
iterator[HttpResponse]
- Raises
ValueError – If the content is not multipart/mixed
-
raise_for_status
()¶ Raises an HttpResponseError if the response has an error status code. If response is good, does nothing.
-
-
class
azure.core.pipeline.transport.
TrioRequestsTransport
(**kwargs: Any)[source]¶ Identical implementation as the synchronous RequestsTransport wrapped in a class with asynchronous methods. Uses the third party trio event loop.
Example:
from azure.core.pipeline.transport import TrioRequestsTransport async with AsyncPipeline(TrioRequestsTransport(), policies=policies) as pipeline: return await pipeline.run(request)
-
close
()¶ Close the session if it is not externally owned.
-
open
()¶ Assign new session if one does not already exist.
-
async
send
(request: azure.core.pipeline.transport._base.HttpRequest, **kwargs: Any) → azure.core.pipeline.transport._base_async.AsyncHttpResponse[source]¶ -
async
send
(request: RestHttpRequest, **kwargs: Any) → RestAsyncHttpResponse Send the request using this HTTP sender.
- Parameters
request (HttpRequest) – The HttpRequest
- Returns
The AsyncHttpResponse
- Return type
- Keyword Arguments
session (requests.Session) – will override the driver session and use yours. Should NOT be done unless really required. Anything else is sent straight to requests.
proxies (dict) – will define the proxy to use. Proxy is a dict (protocol, url)
-
-
class
azure.core.pipeline.transport.
TrioRequestsTransportResponse
(request, requests_response, block_size=None)[source]¶ Asynchronous streaming of data from the response.
-
body
()¶ Return the whole body as bytes in memory.
-
parts
() → collections.abc.AsyncIterator¶ Assuming the content-type is multipart/mixed, will return the parts as an async iterator.
- Return type
AsyncIterator
- Raises
ValueError – If the content is not multipart/mixed
-
raise_for_status
()¶ Raises an HttpResponseError if the response has an error status code. If response is good, does nothing.
-