session#
Summary#
|
A mixin class for |
|
A drop-in replacement for |
Module Contents#
- class CachedSession(base_url=None, *, cache=None, **kwargs)#
Bases:
CacheMixin
,ClientSession
A drop-in replacement for
aiohttp.ClientSession
that adds caching support- Parameters:
cache (
Optional
[CacheBackend
]) – A cache backend object. Seeaiohttp_client_cache.backends
for options. If not provided, an in-memory cache will be used.connector (
aiohttp.BaseConnector
| None) –loop (AbstractEventLoop | None) –
cookies (Mapping[str, str | BaseCookie[str] | Morsel[Any]] | Iterable[Tuple[str, str | BaseCookie[str] | Morsel[Any]]] | BaseCookie[str] | None) –
headers (Mapping[str | istr, str] | CIMultiDict | CIMultiDictProxy | None) –
auth (
aiohttp.BasicAuth
| None) –request_class (Type[ClientRequest]) –
response_class (Type[
aiohttp.ClientResponse
]) –ws_response_class (Type[
aiohttp.ClientWebSocketResponse
]) –version (HttpVersion) –
cookie_jar (AbstractCookieJar | None) –
connector_owner (bool) –
raise_for_status (bool | Callable[[
aiohttp.ClientResponse
], Awaitable[None]]) –read_timeout (float | _SENTINEL) –
conn_timeout (float | None) –
timeout (object |
aiohttp.ClientTimeout
) –auto_decompress (bool) –
trust_env (bool) –
requote_redirect_url (bool) –
trace_configs (List[
aiohttp.TraceConfig
] | None) –read_bufsize (int) –
max_line_size (int) –
max_field_size (int) –
fallback_charset_resolver (Callable[[
aiohttp.ClientResponse
, bytes], str]) –
- async _request(method, str_or_url, expire_after=None, refresh=False, **kwargs)#
Wrapper around
SessionClient._request()
that adds cachingArgs:
- Parameters:
method (
str
) –expire_after (
Union
[None
,int
,float
,str
,datetime
,timedelta
]) –refresh (
bool
) –data (Any) –
json (Any) –
cookies (Mapping[str, str | BaseCookie[str] | Morsel[Any]] | Iterable[Tuple[str, str | BaseCookie[str] | Morsel[Any]]] | BaseCookie[str] | None) –
headers (Mapping[str | istr, str] | CIMultiDict | CIMultiDictProxy | None) –
auth (
aiohttp.BasicAuth
| None) –allow_redirects (bool) –
max_redirects (int) –
compress (str | None) –
chunked (bool | None) –
expect100 (bool) –
raise_for_status (None | bool | Callable[[
aiohttp.ClientResponse
], Awaitable[None]]) –read_until_eof (bool) –
proxy_auth (
aiohttp.BasicAuth
| None) –timeout (
aiohttp.ClientTimeout
| _SENTINEL) –verify_ssl (bool | None) –
fingerprint (bytes | None) –
ssl_context (None) –
ssl (None | Literal[False] | ~aiohttp.client_reqrep.Fingerprint) –
server_hostname (str | None) –
proxy_headers (Mapping[str | istr, str] | CIMultiDict | CIMultiDictProxy | None) –
trace_request_ctx (SimpleNamespace | None) –
read_bufsize (int | None) –
auto_decompress (bool | None) –
max_line_size (int | None) –
max_field_size (int | None) –
- Return type:
- async delete_expired_responses()#
Remove all expired responses from the cache
- disabled()#
Temporarily disable the cache
Example
>>> async with CachedSession() as session: >>> await session.get('http://httpbin.org/ip') >>> async with session.disabled(): >>> # Will return a new response, not a cached one >>> await session.get('http://httpbin.org/ip')
- class CacheMixin(base_url=None, *, cache=None, **kwargs)#
A mixin class for
aiohttp.ClientSession
that adds caching support- Parameters:
cache (
Optional
[CacheBackend
]) –connector (
aiohttp.BaseConnector
| None) –loop (AbstractEventLoop | None) –
cookies (Mapping[str, str | BaseCookie[str] | Morsel[Any]] | Iterable[Tuple[str, str | BaseCookie[str] | Morsel[Any]]] | BaseCookie[str] | None) –
headers (Mapping[str | istr, str] | CIMultiDict | CIMultiDictProxy | None) –
auth (
aiohttp.BasicAuth
| None) –request_class (Type[ClientRequest]) –
response_class (Type[
aiohttp.ClientResponse
]) –ws_response_class (Type[
aiohttp.ClientWebSocketResponse
]) –version (HttpVersion) –
cookie_jar (AbstractCookieJar | None) –
connector_owner (bool) –
raise_for_status (bool | Callable[[
aiohttp.ClientResponse
], Awaitable[None]]) –read_timeout (float | _SENTINEL) –
conn_timeout (float | None) –
timeout (object |
aiohttp.ClientTimeout
) –auto_decompress (bool) –
trust_env (bool) –
requote_redirect_url (bool) –
trace_configs (List[
aiohttp.TraceConfig
] | None) –read_bufsize (int) –
max_line_size (int) –
max_field_size (int) –
fallback_charset_resolver (Callable[[
aiohttp.ClientResponse
, bytes], str]) –