CoreHTTP Library for Python
Project description
Core HTTP shared client library for Python
corehttp provides shared exceptions and modules for Python SDK client libraries.
Getting started
Typically, you will not need to install corehttp, as it will be installed when you install one of the client libraries using it.
Transports
To use corehttp, you will need to choose a transport implementation. corehttp provides the following transports:
Synchronous transports:
RequestsTransport- A synchronous transport based on the Requests library.HttpXTransport- An synchronous transport based on the HTTPX library.
Asynchronous transports:
AioHttpTransport- An asynchronous transport based on the aiohttp library.AsyncHttpXTransport- An asynchronous transport based on the HTTPX library.
Each transport has its own dependencies, which you can install using the corehttp extras:
# Install individually.
pip install corehttp[requests]
pip install corehttp[aiohttp]
pip install corehttp[httpx]
# Install multiple.
pip install corehttp[requests,httpx]
If no transports are specified, corehttp will default to using RequestsTransport for synchronous pipeline requests and AioHttpTransport for asynchronous pipeline requests.
Contributing
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the Microsoft Open Source Code of Conduct. For more information, see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.
Release History
1.0.0b7 (2026-02-05)
Features Added
- Native tracing support was added. #39172
- The
OpenTelemetryTracerclass was added to thecorehttp.instrumentation.tracing.opentelemetrymodule. This is a wrapper around the OpenTelemetry tracer that is used to create spans for SDK operations. - Added a
get_tracermethod to the newcorehttp.instrumentationmodule. This method returns an instance of theOpenTelemetryTracerclass if OpenTelemetry is available. - A
TracingOptionsTypedDict class was added to define the options that SDK users can use to configure tracing per-operation. These options include the ability to enable or disable tracing and set additional attributes on spans.- Example usage:
client.method(tracing_options={"enabled": True, "attributes": {"foo": "bar"}})
- Example usage:
DistributedHttpTracingPolicyanddistributed_trace/distributed_trace_asyncdecorators were added to support OpenTelemetry tracing for SDK operations.- SDK clients can define an
_instrumentation_configclass variable to configure the OpenTelemetry tracer used in method span creation. Possible configuration options arelibrary_name,library_version,schema_url, andattributes.
- SDK clients can define an
- The
- Added a global settings object,
corehttp.settings, to thecorehttppackage. This object can be used to set global settings for thecorehttppackage. Currently the only setting istracing_enabledfor enabling/disabling tracing. #39172 - Added
start_timeandcontextkeyword arguments toOpenTelemetryTracer.start_spanandstart_as_current_spanmethods. - Added
set_span_error_statusstatic method toOpenTelemetryTracerfor setting a span's status to ERROR. - Added
is_generated_model,attribute_list, andTypeHandlerRegistrytocorehttp.serializationmodule for SDK model handling.
Bugs Fixed
- Fixed
retry_backoff_maxbeing ignored in retry policies when configuring retries. - Raise correct exception if transport is used while already closed.
- A timeout error when using the
aiohttptransport will now be raised as acorehttp.exceptions.ServiceResponseTimeoutError, a subtype of the previously raisedServiceResponseError. - When using with
aiohttp3.10 or later, a connection timeout error will now be raised as acorehttp.exceptions.ServiceRequestTimeoutError, which can be retried. - Fixed leaked requests and aiohttp exceptions for streamed responses.
- Improved granularity of
ServiceRequestErrorandServiceResponseErrorexceptions raised in timeout scenarios from the requests and aiohttp transports. BearerTokenCredentialPolicyandAsyncBearerTokenCredentialPolicywill now properly chain exceptions raised during claims challenge handling. If a credential raises an exception when attempting to acquire a token in response to a claims challenge, that exception will be raised with the original 401 response as the cause.
Other Changes
- Added
opentelemetry-apias an optional dependency for tracing. #39172
1.0.0b6 (2025-03-27)
Features Added
- The
TokenCredentialandAsyncTokenCredentialprotocols have been updated to include a newget_token_infomethod. This method should be used to acquire tokens and return anAccessTokenInfoobject. #38346 - Added a new
TokenRequestOptionsclass, which is aTypedDictwith optional parameters, that can be used to define options for token requests through theget_token_infomethod. #38346 - Added a new
AccessTokenInfoclass, which is returned byget_token_infoimplementations. This class contains the token, its expiration time, and optional additional information like when a token should be refreshed. #38346 BearerTokenCredentialPolicyandAsyncBearerTokenCredentialPolicynow check if a credential has theget_token_infomethod defined. If so, theget_token_infomethod is used to acquire a token. #38346- These policies now also check the
refresh_onattribute when determining if a new token request should be made.
- These policies now also check the
- Added
modelattribute toHttpResponseErrorto allow accessing error attributes based on a known model. #39636 - Added
auth_flowssupport inBearerTokenCredentialPolicy. #40084
Breaking Changes
- The
get_tokenmethod has been removed from theTokenCredentialandAsyncTokenCredentialprotocols. Implementations should now use the newget_token_infomethod to acquire tokens. #38346 - The
AccessTokenclass has been removed and replaced with a newAccessTokenInfoclass. #38346 BearerTokenCredentialPolicyandAsyncBearerTokenCredentialPolicynow rely on credentials having theget_token_infomethod defined. #38346
1.0.0b5 (2024-02-29)
Other Changes
- Accept float for
retry_afterheader.
1.0.0b4 (2024-02-23)
Other Changes
- Relax type checking in
Pipelineconstructors to only check that each user-supplied policy object has either asendmethod or both anon_requestandon_responsemethod. This allows for more flexible policy implementations. #34296
1.0.0b3 (2024-02-01)
Features Added
- Support tuple input for
filesvalues tocorehttp.rest.HttpRequest#34082 - Support simultaneous
filesanddatafield entry intocorehttp.rest.HttpRequest#34082
1.0.0b2 (2023-11-14)
Features Added
- Added the initial implementation of the HTTPX transport. #32813
Breaking Changes
- Removed
requestsas a default dependency ofcorehttp. This is now an "extras" dependency and can be installed viacorehttp[requests]. #32813 - Renamed the
aioextra toaiohttp. #32813
Bugs Fixed
- Fixed an issue with
multipart/form-datain the async transport wheredatawas not getting encoded into the request body. #32473 - Fixed an issue with
connection_verify,connection_cert, andconnection_timeoutnot being propagated to underlying transports. #33057 - Fixed an issue with the
aiohttptransport not using SSL by default. #33057
Other Changes
- Added extras for
httpx. #32813
1.0.0b1 (2023-10-18)
- Initial Release
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file corehttp-1.0.0b7.tar.gz.
File metadata
- Download URL: corehttp-1.0.0b7.tar.gz
- Upload date:
- Size: 138.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: RestSharp/106.13.0.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f21b71028a62e67e346f4669590b1285afa09145d39a50573b3cfabf9c7b2457
|
|
| MD5 |
77545b9c6ac38d639750bf9d788c8c57
|
|
| BLAKE2b-256 |
da3facca3087de1a2ade283839565a7af0af15a5cb99d90f159920cd84ffa540
|
File details
Details for the file corehttp-1.0.0b7-py3-none-any.whl.
File metadata
- Download URL: corehttp-1.0.0b7-py3-none-any.whl
- Upload date:
- Size: 121.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: RestSharp/106.13.0.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d20d0291407458789298fbee27a551a60156a1ba23a8fd27ec0a0e63c48f8718
|
|
| MD5 |
e684c850e93f7fa4812dfdb8542472e6
|
|
| BLAKE2b-256 |
652467106f097be23a49588e2c6d680d8cb2ccb80c0ddc844083a5f2cd5f6ca4
|