Available Session Implementations
You can choose which HTTP library will be used by Client
and AsyncClient
by specifying the session
parameter.
Below you can see the list of session implementations that are shipped with the yadisk
library.
Alternatively, you can make your own Session
/AsyncSession
implementation.
For a concrete example, take a look at the source code of any existing implementations (e.g. HTTPXSession
).
Synchronous Implementations
- class yadisk.sessions.requests_session.RequestsSession(*args, **kwargs)[source]
Bases:
Session
Session
implementation using the requests library.All arguments passed in the constructor are directly forwared to
requests.Session
.- Variables:
requests_session – underlying instance of
requests.Session
Note
Internally, this class creates thread-local instances of
requests.Session
, since it is not currently guaranteed to be thread safe. CallingSession.close()
will close all thread-local sessions managed by this object.To pass requests-specific arguments from
Client
userequests_args
keyword argument.Usage example:
import yadisk with yadisk.Client(..., session="requests") as client: client.get_meta( "/my_file.txt", n_retries=5, requests_args={ "proxies": {"https": "http://example.com:1234"}, "verify": False } )
- class yadisk.sessions.httpx_session.HTTPXSession(*args, **kwargs)[source]
Bases:
Session
Session
implementation using the httpx library.All arguments passed in the constructor are directly forwared to httpx.Client.
- Variables:
httpx_client – underlying instance of httpx.Client
To pass httpx-specific arguments from
Client
usehttpx_args
keyword argument.Usage example:
import yadisk with yadisk.Client(..., session="httpx") as client: client.get_meta( "/my_file.txt", n_retries=5, httpx_args={ "proxies":"http://localhost:11234", "verify": False, "max_redirects": 10 } )
- class yadisk.sessions.pycurl_session.PycURLSession[source]
Bases:
Session
Session
implementation using the pycurl library.To pass pycurl-specific arguments from
Client
usecurl_options
keyword argument.Usage example:
import yadisk import pycurl with yadisk.Client(..., session="pycurl") as client: client.get_meta( "/my_file.txt", n_retries=5, curl_options={ pycurl.MAX_SEND_SPEED_LARGE: 5 * 1024**2, pycurl.MAX_RECV_SPEED_LARGE: 5 * 1024**2, pycurl.PROXY: "http://localhost:12345", pycurl.MAXREDIRS: 15 } )
Asynchronous Implementations
- class yadisk.sessions.aiohttp_session.AIOHTTPSession(*args, **kwargs)[source]
Bases:
AsyncSession
AsyncSession
implementation using the aiohttp library.All arguments passed in the constructor are directly forwared to
aiohttp.ClientSession
.- Variables:
aiohttp_session – underlying instance of
aiohttp.ClientSession
To pass aiohttp-specific arguments from
AsyncClient
useaiohttp_args
keyword argument.Usage example:
import yadisk async def main(): async with yadisk.AsyncClient(..., session="aiohttp") as client: await client.get_meta( "/my_file.txt", n_retries=5, aiohttp_args={ "proxies": {"https": "http://example.com:1234"}, "verify": False } )
- class yadisk.sessions.async_httpx_session.AsyncHTTPXSession(*args, **kwargs)[source]
Bases:
AsyncSession
AsyncSession
implementation using the httpx library.All arguments passed in the constructor are directly forwared to httpx.AsyncClient.
- Variables:
httpx_client – underlying instance of httpx.AsyncClient
To pass httpx-specific arguments from
AsyncClient
usehttpx_args
keyword argument.Usage example:
import yadisk async def main(): async with yadisk.AsyncClient(..., session="httpx") as client: await client.get_meta( "/my_file.txt", n_retries=5, httpx_args={ "proxies":"http://localhost:11234", "verify": False, "max_redirects": 10 } )
Importing Session Classes
You can use the following functions to import a session class by name:
- yadisk.import_session(name: SessionName) Type[Session] [source]
Imports relevant session class based on provided name.
The following sessions are available:
"httpx"
-HTTPXSession
"pycurl"
-PycURLSession
"requests"
-RequestsSession
- Parameters:
name – str, session name
- Raises:
ImportError – could not import module
ValueError – unknown name
- Returns:
subclass of
Session
- yadisk.import_async_session(name: AsyncSessionName) Type[AsyncSession] [source]
Imports relevant asynchronous session class based on provided name.
- Parameters:
name – str, session name
The following sessions are available:
"aiohttp"
-AIOHTTPSession
"httpx"
-AsyncHTTPXSession
- Raises:
ImportError – could not import module
ValueError – unknown name
- Returns:
subclass of
AsyncSession