From 73300e098c6cf69c3ae745abcf79252d795abd1d Mon Sep 17 00:00:00 2001 From: Laurent Mazuel Date: Thu, 13 Oct 2022 08:43:38 -0700 Subject: [PATCH] Add more example of transport (#26768) * Add more example of transport See https://github.com/Azure/azure-sdk-for-python/pull/26757 * Update CLIENT_LIBRARY_DEVELOPER.md * Update CLIENT_LIBRARY_DEVELOPER.md * Update CLIENT_LIBRARY_DEVELOPER.md * Update CLIENT_LIBRARY_DEVELOPER.md Co-authored-by: Xiang Yan --- sdk/core/azure-core/CLIENT_LIBRARY_DEVELOPER.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/sdk/core/azure-core/CLIENT_LIBRARY_DEVELOPER.md b/sdk/core/azure-core/CLIENT_LIBRARY_DEVELOPER.md index 36c5933986a8..0ca157a83037 100644 --- a/sdk/core/azure-core/CLIENT_LIBRARY_DEVELOPER.md +++ b/sdk/core/azure-core/CLIENT_LIBRARY_DEVELOPER.md @@ -113,6 +113,22 @@ from azure.core.pipeline.transport import RequestsTransport synchronous_transport = RequestsTransport() ``` +For example if you would like to alter connection pool you can initialise `RequestsTransport` with an instance of `requests.Session`. + + ```Python + import requests + from azure.core.pipeline.transport import RequestsTransport + session = requests.Session() + adapter = requests.adapters.HTTPAdapter(pool_connections=42, pool_maxsize=42) + session.mount('https://', adapter) + client = FooServiceClient(endpoint, creds, transport=RequestsTransport(session=session, session_owner=False)) + + # Here we want to manage the session by ourselves. When we are done with the session, we need to close the session. + session.close() + + # Note: `session_owner` gives the information of ownership of the requests sessions to the transport instance, to authorize it to close on customer's behalf. If you're ok that the client closes your session on your behalf as necessary, you don't need to pass a value. + ``` + For asynchronous pipelines a couple of transport options are available. Each of these transports are interchangable depending on whether the user has installed various 3rd party dependencies (i.e. aiohttp or trio), and the user should easily be able to specify their chosen transport. SDK developers should use the `aiohttp` transport as the default for asynchronous pipelines where the user has not specified an alternative.