corehttp.runtime package

class corehttp.runtime.AsyncPipelineClient(endpoint: str, *, pipeline: AsyncPipeline[HTTPRequestType, AsyncHTTPResponseType] | None = None, **kwargs: Any)[source]

Service client core methods.

Builds an AsyncPipeline client.

Parameters:

endpoint (str) – URL for the request.

Keyword Arguments:
Variables:

pipeline (Pipeline or None) – The Pipeline object associated with the client.

Example:

Builds the async pipeline client.
from corehttp.runtime import AsyncPipelineClient
from corehttp.rest import HttpRequest, AsyncHttpResponse
from corehttp.runtime.policies import (
    AsyncHTTPPolicy,
    SansIOHTTPPolicy,
    HeadersPolicy,
    UserAgentPolicy,
    AsyncRetryPolicy,
)

policies: Iterable[Union[AsyncHTTPPolicy, SansIOHTTPPolicy]] = [
    HeadersPolicy(),
    UserAgentPolicy("myuseragent"),
    AsyncRetryPolicy(),
]
client: AsyncPipelineClient[HttpRequest, AsyncHttpResponse] = AsyncPipelineClient(
    "https://bing.com", policies=policies
)
request = HttpRequest("GET", "https://bing.com")
async with client:
    response = await client.send_request(request)
async close() None[source]
format_url(url_template: str, **kwargs: Any) str

Format request URL with the client base URL, unless the supplied URL is already absolute.

Note that both the base url and the template url can contain query parameters.

Parameters:

url_template (str) – The request URL to be formatted if necessary.

Return type:

str

Returns:

The formatted URL.

send_request(request: HTTPRequestType, *, stream: bool = False, **kwargs: Any) Awaitable[AsyncHTTPResponseType][source]

Method that runs the network request through the client’s chained policies.

>>> from corehttp.rest import HttpRequest
>>> request = HttpRequest('GET', 'http://www.example.com')
<HttpRequest [GET], url: 'http://www.example.com'>
>>> response = await client.send_request(request)
<AsyncHttpResponse: 200 OK>
Parameters:

request (HttpRequest) – The network request you want to make. Required.

Keyword Arguments:

stream (bool) – Whether the response payload will be streamed. Defaults to False.

Returns:

The response of your network call. Does not do error handling on your response.

Return type:

AsyncHttpResponse

class corehttp.runtime.PipelineClient(endpoint: str, *, pipeline: Pipeline[HTTPRequestType, HTTPResponseType] | None = None, **kwargs: Any)[source]

Service client core methods.

Builds a Pipeline client.

Parameters:

endpoint (str) – URL for the request.

Keyword Arguments:
Variables:

pipeline (Pipeline or None) – The Pipeline object associated with the client.

Example:

Builds the pipeline client.
from corehttp.runtime import PipelineClient
from corehttp.rest import HttpRequest, HttpResponse
from corehttp.runtime.policies import (
    HTTPPolicy,
    SansIOHTTPPolicy,
    HeadersPolicy,
    UserAgentPolicy,
    RetryPolicy,
)

policies: Iterable[Union[HTTPPolicy, SansIOHTTPPolicy]] = [
    HeadersPolicy(),
    UserAgentPolicy("myuseragent"),
    RetryPolicy(),
]

client: PipelineClient[HttpRequest, HttpResponse] = PipelineClient("https://bing.com", policies=policies)
request = HttpRequest("GET", "https://bing.com")
response = client.send_request(request)
close() None[source]
format_url(url_template: str, **kwargs: Any) str

Format request URL with the client base URL, unless the supplied URL is already absolute.

Note that both the base url and the template url can contain query parameters.

Parameters:

url_template (str) – The request URL to be formatted if necessary.

Return type:

str

Returns:

The formatted URL.

send_request(request: HTTPRequestType, *, stream: bool = False, **kwargs: Any) HTTPResponseType[source]

Method that runs the network request through the client’s chained policies.

>>> from corehttp.rest import HttpRequest
>>> request = HttpRequest('GET', 'http://www.example.com')
<HttpRequest [GET], url: 'http://www.example.com'>
>>> response = client.send_request(request)
<HttpResponse: 200 OK>
Parameters:

request (HttpRequest) – The network request you want to make. Required.

Keyword Arguments:

stream (bool) – Whether the response payload will be streamed. Defaults to False.

Returns:

The response of your network call. Does not do error handling on your response.

Return type:

HttpResponse

Subpackages