Azure / Azure/azure-sdk-for-python
Add HttpxTransport support for SDK
@xiangyan99 y travaille déjà.
Depuis le 2/6/2025.
- Langage dominant
- Python
- Étoiles
- 5.6k
- Forks
- 3.4k
- Merge moyen
- 2 j 2 h
- PR mergées (30 j)
- 213
Description
Context
Today, we do not pre-installed any async http libs, and if people try they get this:
ImportError: aiohttp package is not installed
This prompt people to install aiohttp to execute async code. While aiohttp is installed, we automatically loads it by default:
https://github.com/Azure/azure-sdk-for-python/blob/9e75dc54f8f39ca210f04438aaf0f4302dc82b37/sdk/core/azure-core/azure/core/_pipeline_client_async.py#L258-L262
I'd like to add httpx in the mix, and make it the recommendation for async.
Proposal
- Add
HttpxTransporttoazure-core - Make the default behavior as follow:
- If no async transport found, raise an ImportError about
httpx - If only httpx is found, load it as async transport
- If
aiohttpis found (with or withouthttpxinstalled), use it as async transport
- If no async transport found, raise an ImportError about
- Add a setting in azure.core settings called
default_sync_transportanddefault_async_transport- We can set it for
httpxto make it the default independently ofrequestsoraiohttpbeing installed - We accept an instance, in which case this instance becomes the default transport of all SDK. This helps customers pass their own transport if they want to, without having to use
transport=in all SDK.
- We can set it for
- (Optional) Let's add transport information in UserAgent to monitor what is happening and get numbers
Notes
- The only behavioral change, is that if
httpxis installed, instead of raising an exception that async is not available, not it works withhttpx. That's not a breaking change in my book, I don't see how this could break anyone that except their code to raise. - We can discuss longer term to shift the default
- This gives an easy escape hatch in case of troubles
- Our transport layer is supposed to hide implementation details, therefore I don't consider the fact that
httpxis not GA as a problem. As far as I am aware, OpenAI is doing just fine.
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Évaluation
Cette issue n'a pas encore été évaluée.