Skip to content

Commit

Permalink
Add more example of transport (#26768)
Browse files Browse the repository at this point in the history
* 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 <xiangsjtu@gmail.com>
  • Loading branch information
lmazuel and xiangyan99 authored Oct 13, 2022
1 parent 64ef8f9 commit 73300e0
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions sdk/core/azure-core/CLIENT_LIBRARY_DEVELOPER.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down

0 comments on commit 73300e0

Please sign in to comment.