Patcher#

Utilities for patching requests. See Patching for general usage info.

Warning

These functions are not thread-safe. Use CachedSession if you want to use caching in a multi-threaded environment.

clear

Clear the currently installed cache (if any)

delete

Remove responses from the cache according one or more conditions. See :py:meth:`.BaseCache.delete for usage details.

disabled

Context manager for temporarily disabling caching for all requests functions

enabled

Context manager for temporarily enabling caching for all requests functions

get_cache

Get the internal cache object from the currently installed CachedSession (if any)

install_cache

Install the cache for all requests functions by monkey-patching requests.Session

is_installed

Indicate whether or not requests-cache is currently installed

remove_expired_responses

Remove expired responses from the cache

uninstall_cache

Disable the cache by restoring the original requests.Session

requests_cache.patcher.clear()[source]#

Clear the currently installed cache (if any)

requests_cache.patcher.delete(*args, **kwargs)[source]#

Remove responses from the cache according one or more conditions. See :py:meth:`.BaseCache.delete for usage details.

requests_cache.patcher.disabled()[source]#

Context manager for temporarily disabling caching for all requests functions

Example

>>> with requests_cache.disabled():
...     requests.get('https://httpbin.org/get')
requests_cache.patcher.enabled(*args, **kwargs)[source]#

Context manager for temporarily enabling caching for all requests functions

Example

>>> with requests_cache.enabled('cache.db'):
...     requests.get('https://httpbin.org/get')

Accepts the same arguments as CachedSession and install_cache().

requests_cache.patcher.get_cache()[source]#

Get the internal cache object from the currently installed CachedSession (if any)

Return type:

Optional[BaseCache]

requests_cache.patcher.install_cache(cache_name='http_cache', backend=None, session_factory=<class 'requests_cache.session.CachedSession'>, **kwargs)[source]#

Install the cache for all requests functions by monkey-patching requests.Session

Example

>>> requests_cache.install_cache('demo_cache')

Accepts all the same parameters as CachedSession. Additional parameters:

Parameters:
requests_cache.patcher.is_installed()[source]#

Indicate whether or not requests-cache is currently installed

Return type:

bool

requests_cache.patcher.remove_expired_responses()[source]#

Remove expired responses from the cache

requests_cache.patcher.uninstall_cache()[source]#

Disable the cache by restoring the original requests.Session