azure.core.pipeline

class azure.core.pipeline.Pipeline(transport, policies=None)[source]

A pipeline implementation.

This is implemented as a context manager, that will activate the context of the HTTP sender. The transport is the last node in the pipeline.

Parameters
  • transport – The Http Transport instance

  • policies (list) – List of configured policies.

Example:

Builds the pipeline for synchronous transport.
from azure.core.pipeline import Pipeline
from azure.core.pipeline.policies import RedirectPolicy, UserAgentPolicy
from azure.core.pipeline.transport import RequestsTransport, HttpRequest

# example: create request and policies
request = HttpRequest("GET", "https://bing.com")
policies = [
    UserAgentPolicy("myuseragent"),
    RedirectPolicy()
]

# run the pipeline
with Pipeline(transport=RequestsTransport(), policies=policies) as pipeline:
    response = pipeline.run(request)
run(request, **kwargs)[source]

Runs the HTTP Request through the chained policies.

Parameters

request (HttpRequest) – The HTTP request object.

Returns

The PipelineResponse object

Return type

PipelineResponse

class azure.core.pipeline.PipelineRequest(http_request, context)[source]

A pipeline request object.

Container for moving the HttpRequest through the pipeline. Universal for all transports, both synchronous and asynchronous.

Parameters
  • http_request (HttpRequest) – The request object.

  • context (PipelineContext) – Contains the context - data persisted between pipeline requests.

class azure.core.pipeline.PipelineResponse(http_request, http_response, context)[source]

A pipeline response object.

The PipelineResponse interface exposes an HTTP response object as it returns through the pipeline of Policy objects. This ensures that Policy objects have access to the HTTP response.

This also has a “context” object where policy can put additional fields. Policy SHOULD update the “context” with additional post-processed field if they create them. However, nothing prevents a policy to actually sub-class this class a return it instead of the initial instance.

Parameters
  • http_request (HttpRequest) – The request object.

  • http_response (HttpResponse) – The response object.

  • context (PipelineContext) – Contains the context - data persisted between pipeline requests.

class azure.core.pipeline.PipelineContext(transport, **kwargs)[source]

A context object carried by the pipeline request and response containers.

This is transport specific and can contain data persisted between pipeline requests (for example reusing an open connection pool or “session”), as well as used by the SDK developer to carry arbitrary data through the pipeline.

Parameters
  • transport – The HTTP transport type.

  • kwargs – Developer-defined keyword arguments.

clear()[source]

Context objects cannot be cleared.

Raises

TypeError

copy() → a shallow copy of D
fromkeys()

Returns a new dict with keys from iterable and values equal to value.

get(k[, d]) → D[k] if k in D, else d. d defaults to None.
items() → a set-like object providing a view on D's items
keys() → a set-like object providing a view on D's keys
pop(*args)[source]

Removes specified key and returns the value.

popitem() → (k, v), remove and return some (key, value) pair as a

2-tuple; but raise KeyError if D is empty.

setdefault(k[, d]) → D.get(k,d), also set D[k]=d if k not in D
update(*args, **kwargs)[source]

Context objects cannot be updated.

Raises

TypeError

values() → an object providing a view on D's values
class azure.core.pipeline.AsyncPipeline(transport, policies: List[Union[azure.core.pipeline.policies._base_async.AsyncHTTPPolicy, azure.core.pipeline.policies._base.SansIOHTTPPolicy]] = None)[source]

Async pipeline implementation.

This is implemented as a context manager, that will activate the context of the HTTP sender.

Parameters
  • transport – The async Http Transport instance.

  • policies (list) – List of configured policies.

Example:

Builds the async pipeline for asynchronous transport.
from azure.core.pipeline import AsyncPipeline
from azure.core.pipeline.policies import AsyncRedirectPolicy, UserAgentPolicy
from azure.core.pipeline.transport import AioHttpTransport, HttpRequest

# example: create request and policies
request = HttpRequest("GET", "https://bing.com")
policies = [
    UserAgentPolicy("myuseragent"),
    AsyncRedirectPolicy()
]

# run the pipeline
async with AsyncPipeline(transport=AioHttpTransport(), policies=policies) as pipeline:
    response = await pipeline.run(request)
async run(request: HTTPRequestType, **kwargs: Any)[source]

Runs the HTTP Request through the chained policies.

Parameters

request (HttpRequest) – The HTTP request object.

Returns

The PipelineResponse object.

Return type

PipelineResponse