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:
pipeline (Pipeline) – If omitted, a Pipeline object is created.
policies (list[AsyncHTTPPolicy]) – If omitted, a set of standard policies isI be used.
per_call_policies (Union[AsyncHTTPPolicy, SansIOHTTPPolicy, list[AsyncHTTPPolicy], list[SansIOHTTPPolicy]]) – If specified, the policies will be added into the policy list before RetryPolicy
per_retry_policies (Union[AsyncHTTPPolicy, SansIOHTTPPolicy, list[AsyncHTTPPolicy], list[SansIOHTTPPolicy]]) – If specified, the policies will be added into the policy list after RetryPolicy
transport (AsyncHttpTransport) – If omitted, AioHttpTransport is used for asynchronous transport.
- 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)
- 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.
- 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:
- 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:
pipeline (Pipeline) – If omitted, a Pipeline object is created.
policies (list[HTTPPolicy]) – If omitted, a set of standard policies is used.
per_call_policies (Union[HTTPPolicy, SansIOHTTPPolicy, list[HTTPPolicy], list[SansIOHTTPPolicy]]) – If specified, the policies will be added into the policy list before RetryPolicy
per_retry_policies (Union[HTTPPolicy, SansIOHTTPPolicy, list[HTTPPolicy], list[SansIOHTTPPolicy]]) – If specified, the policies will be added into the policy list after RetryPolicy
transport (HttpTransport) – If omitted, RequestsTransport is used for synchronous transport.
- 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)
- 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.
- 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:
Subpackages¶
- corehttp.runtime.pipeline package
- corehttp.runtime.policies package
AsyncBearerTokenCredentialPolicy
AsyncBearerTokenCredentialPolicy.authorize_request()
AsyncBearerTokenCredentialPolicy.on_challenge()
AsyncBearerTokenCredentialPolicy.on_exception()
AsyncBearerTokenCredentialPolicy.on_request()
AsyncBearerTokenCredentialPolicy.on_response()
AsyncBearerTokenCredentialPolicy.send()
AsyncBearerTokenCredentialPolicy.next
AsyncHTTPPolicy
AsyncRetryPolicy
AsyncRetryPolicy.configure_retries()
AsyncRetryPolicy.get_backoff_time()
AsyncRetryPolicy.get_retry_after()
AsyncRetryPolicy.increment()
AsyncRetryPolicy.is_exhausted()
AsyncRetryPolicy.is_retry()
AsyncRetryPolicy.no_retries()
AsyncRetryPolicy.parse_retry_after()
AsyncRetryPolicy.send()
AsyncRetryPolicy.sleep()
AsyncRetryPolicy.update_context()
AsyncRetryPolicy.BACKOFF_MAX
AsyncRetryPolicy.next
BearerTokenCredentialPolicy
ContentDecodePolicy
HTTPPolicy
HeadersPolicy
NetworkTraceLoggingPolicy
ProxyPolicy
RequestHistory
RetryMode
RetryMode.capitalize()
RetryMode.casefold()
RetryMode.center()
RetryMode.count()
RetryMode.encode()
RetryMode.endswith()
RetryMode.expandtabs()
RetryMode.find()
RetryMode.format()
RetryMode.format_map()
RetryMode.index()
RetryMode.isalnum()
RetryMode.isalpha()
RetryMode.isascii()
RetryMode.isdecimal()
RetryMode.isdigit()
RetryMode.isidentifier()
RetryMode.islower()
RetryMode.isnumeric()
RetryMode.isprintable()
RetryMode.isspace()
RetryMode.istitle()
RetryMode.isupper()
RetryMode.join()
RetryMode.ljust()
RetryMode.lower()
RetryMode.lstrip()
RetryMode.maketrans()
RetryMode.partition()
RetryMode.removeprefix()
RetryMode.removesuffix()
RetryMode.replace()
RetryMode.rfind()
RetryMode.rindex()
RetryMode.rjust()
RetryMode.rpartition()
RetryMode.rsplit()
RetryMode.rstrip()
RetryMode.split()
RetryMode.splitlines()
RetryMode.startswith()
RetryMode.strip()
RetryMode.swapcase()
RetryMode.title()
RetryMode.translate()
RetryMode.upper()
RetryMode.zfill()
RetryMode.Exponential
RetryMode.Fixed
RetryPolicy
RetryPolicy.configure_retries()
RetryPolicy.get_backoff_time()
RetryPolicy.get_retry_after()
RetryPolicy.increment()
RetryPolicy.is_exhausted()
RetryPolicy.is_retry()
RetryPolicy.no_retries()
RetryPolicy.parse_retry_after()
RetryPolicy.send()
RetryPolicy.sleep()
RetryPolicy.update_context()
RetryPolicy.BACKOFF_MAX
RetryPolicy.next
SansIOHTTPPolicy
ServiceKeyCredentialPolicy
UserAgentPolicy