Azure / Azure/azure-sdk-for-python

Add HttpxTransport support for SDK

Ouverte
#41,382 4 commentaires 3 réactions 1 personne assignée Voir sur GitHub

@xiangyan99 y travaille déjà.

Depuis le 2/6/2025.

feature-request
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 HttpxTransport to azure-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 aiohttp is found (with or without httpx installed), use it as async transport
  • Add a setting in azure.core settings called default_sync_transport and default_async_transport
    • We can set it for httpx to make it the default independently of requests or aiohttp being 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.
  • (Optional) Let's add transport information in UserAgent to monitor what is happening and get numbers

Notes

  • The only behavioral change, is that if httpx is installed, instead of raising an exception that async is not available, not it works with httpx. 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 httpx is 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

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.