azure.core.pipeline.transport package

Module contents

class azure.core.pipeline.transport.HttpTransport[source]

Bases: contextlib.AbstractContextManager, abc.ABC, typing.Generic

An http sender ABC.

close()[source]

Close the session if it is not externally owned.

open()[source]

Assign new session if one does not already exist.

send(request, **kwargs)[source]

Send the request using this HTTP sender.

Parameters:request (PipelineRequest) – The pipeline request object
Returns:The pipeline response object.
Return type:PipelineResponse
sleep(duration)[source]
class azure.core.pipeline.transport.HttpRequest(method, url, headers=None, files=None, data=None)[source]

Bases: object

Represents a HTTP request.

URL can be given without query parameters, to be added later using “format_parameters”.

Parameters:
  • method (str) – HTTP method (GET, HEAD, etc.)
  • url (str) – At least complete scheme/host/path
  • headers (dict[str,str]) – HTTP headers
  • files – Files list.
  • data (bytes or str.) – Body to be sent.
format_parameters(params)[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()[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.

serialize()[source]

Serialize this request using application/http spec.

Return type:bytes
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, **kwargs)[source]

Set the part of a multipart/mixed.

Only support 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.

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_xml_body(data)[source]

Set an XML element tree as the body of the request.

Parameters:data (XML node) – The request field data.
body

Alias to data.

Return type:bytes
query

The query parameters of the request as a dict.

Return type:dict[str, str]
class azure.core.pipeline.transport.HttpResponse(request, internal_response, block_size=None)[source]

Bases: azure.core.pipeline.transport._base._HttpResponseBase

parts()[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
stream_download(pipeline)[source]

Generator for streaming request body data.

Should be implemented by sub-classes if streaming download is supported.

Return type:iterator[bytes]
class azure.core.pipeline.transport.RequestsTransport(**kwargs)[source]

Bases: azure.core.pipeline.transport._base.HttpTransport

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:

close()[source]

Close the session if it is not externally owned.

open()[source]

Assign new session if one does not already exist.

send(request, **kwargs)[source]

Send request object according to configuration.

Parameters:

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

Returns:

An HTTPResponse object.

Return type:

HttpResponse

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.RequestsTransportResponse(request, requests_response, block_size=None)[source]

Bases: azure.core.pipeline.transport._base.HttpResponse, azure.core.pipeline.transport._requests_basic._RequestsTransportResponseBase

Streaming of data from the response.

stream_download(pipeline)[source]

Generator for streaming request body data.

class azure.core.pipeline.transport.AsyncHttpTransport[source]

Bases: contextlib.AbstractAsyncContextManager, abc.ABC, typing.Generic

An http sender ABC.

close()[source]

Close the session if it is not externally owned.

open()[source]

Assign new session if one does not already exist.

send(request, **kwargs)[source]

Send the request using this HTTP sender.

sleep(duration)[source]
class azure.core.pipeline.transport.AsyncHttpResponse(request, internal_response, block_size=None)[source]

Bases: azure.core.pipeline.transport._base._HttpResponseBase

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
stream_download(pipeline) → 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) – The pipeline object
class azure.core.pipeline.transport.AsyncioRequestsTransport(**kwargs)[source]

Bases: azure.core.pipeline.transport._base_requests_async.RequestsAsyncTransportBase

Identical implementation as the synchronous RequestsTransport wrapped in a class with asynchronous methods. Uses the built-in asyncio event loop.

Example:

send(request: azure.core.pipeline.transport._base.HttpRequest, **kwargs) → azure.core.pipeline.transport._base_async.AsyncHttpResponse[source]

Send the request using this HTTP sender.

Parameters:

request (HttpRequest) – The HttpRequest

Returns:

The AsyncHttpResponse

Return type:

AsyncHttpResponse

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)[source]
class azure.core.pipeline.transport.AsyncioRequestsTransportResponse(request, requests_response, block_size=None)[source]

Bases: azure.core.pipeline.transport._base_async.AsyncHttpResponse, azure.core.pipeline.transport._requests_basic.RequestsTransportResponse

Asynchronous streaming of data from the response.

stream_download(pipeline) → AsyncIterator[bytes][source]

Generator for streaming request body data.

class azure.core.pipeline.transport.AioHttpTransport(*, session=None, loop=None, session_owner=True, **kwargs)[source]

Bases: azure.core.pipeline.transport._base_async.AsyncHttpTransport

AioHttp HTTP sender implementation.

Fully asynchronous implementation using the aiohttp library.

Parameters:
  • session – The client session.
  • loop – The event loop.
  • session_owner (bool) – Session owner. Defaults True.
Keyword Arguments:
 

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

Example:

close()[source]

Closes the connection.

open()[source]

Opens the connection.

send(request: azure.core.pipeline.transport._base.HttpRequest, **config) → Optional[azure.core.pipeline.transport._base_async.AsyncHttpResponse][source]

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:

AsyncHttpResponse

Keyword Arguments:
 
  • stream (bool) – Defaults to False.
  • proxies (dict) – dict of proxy to used based on protocol. Proxy is a dict (protocol, url)
  • proxy (str) – will define the proxy to use all the time
class azure.core.pipeline.transport.AioHttpTransportResponse(request: azure.core.pipeline.transport._base.HttpRequest, aiohttp_response: aiohttp.client_reqrep.ClientResponse, block_size=None)[source]

Bases: azure.core.pipeline.transport._base_async.AsyncHttpResponse

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.
body() → bytes[source]

Return the whole body as bytes in memory.

load_body() → None[source]

Load in memory the body, so it could be accessible from sync methods.

stream_download(pipeline) → AsyncIterator[bytes][source]

Generator for streaming response body data.

Parameters:pipeline (azure.core.pipeline) – The pipeline object