Skip to content

Commit 73300e0

Browse files
lmazuelxiangyan99
andauthored
Add more example of transport (#26768)
* Add more example of transport See #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 <[email protected]>
1 parent 64ef8f9 commit 73300e0

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

sdk/core/azure-core/CLIENT_LIBRARY_DEVELOPER.md

+16
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,22 @@ from azure.core.pipeline.transport import RequestsTransport
113113
synchronous_transport = RequestsTransport()
114114
```
115115

116+
For example if you would like to alter connection pool you can initialise `RequestsTransport` with an instance of `requests.Session`.
117+
118+
```Python
119+
import requests
120+
from azure.core.pipeline.transport import RequestsTransport
121+
session = requests.Session()
122+
adapter = requests.adapters.HTTPAdapter(pool_connections=42, pool_maxsize=42)
123+
session.mount('https://', adapter)
124+
client = FooServiceClient(endpoint, creds, transport=RequestsTransport(session=session, session_owner=False))
125+
126+
# Here we want to manage the session by ourselves. When we are done with the session, we need to close the session.
127+
session.close()
128+
129+
# 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.
130+
```
131+
116132
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
117133
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.
118134

0 commit comments

Comments
 (0)