The Python SDKs now support interface-driven HTTP client injection and direct use of a requests.Session instance, improving developer experience, flexibility and alignment with other SDKs.
Developers can now either implement the HttpClientProvider interface for structured control if the intention is to override the timeout property or directly provide a requests.Session for simple customization. This enhancement streamlines the custom http client injection while remaining backward compatible.
Example Usage
import requests
from requests import Session
from myapi.http.http_client_provider import HttpClientProvider
class CustomHttpClient(HttpClientProvider):
def __init__(self, timeout=10):
self._session = requests.Session()
self.session.headers.update({
"Authorization": "Bearer your-access-token",
"Custom-Header": "CustomValue",
})
self._timeout = timeout
@property
def timeout(self) -> float:
return self._timeout
@property
def session(self) -> Session:
return self._session
client = Myapi(
http_client_instance=CustomHttpClient(), # Interface-driven
# or
# http_client_instance=requests.Session(), # Plain Session
override_http_client_configuration=True
)
Learn more about configurable http clients feature