Patcher#
Utilities for patching requests
.
Warning
These functions are not thread-safe. Use CachedSession
if you want to use
caching in a multi-threaded environment.
Clear the currently installed cache (if any) |
|
Context manager for temporarily disabling caching for all |
|
Context manager for temporarily enabling caching for all |
|
Get the internal cache object from the currently installed |
|
Install the cache for all |
|
Indicate whether or not requests-cache is currently installed |
|
Remove expired responses from the cache, optionally with revalidation |
|
Disable the cache by restoring the original |
- requests_cache.patcher.disabled()[source]#
Context manager for temporarily disabling caching for all
requests
functionsExample
>>> with requests_cache.disabled(): ... requests.get('http://httpbin.org/get')
- requests_cache.patcher.enabled(*args, **kwargs)[source]#
Context manager for temporarily enabling caching for all
requests
functionsAccepts the same arguments as
install_cache()
.Example
>>> with requests_cache.enabled('cache_db'): ... requests.get('http://httpbin.org/get')
- requests_cache.patcher.get_cache()[source]#
Get the internal cache object from the currently installed
CachedSession
(if any)
- requests_cache.patcher.install_cache(cache_name='http_cache', backend=None, expire_after=-1, urls_expire_after=None, allowable_codes=(200, ), allowable_methods=('GET', 'HEAD'), filter_fn=None, stale_if_error=False, session_factory=<class 'requests_cache.session.CachedSession'>, **kwargs)[source]#
Install the cache for all
requests
functions by monkey-patchingrequests.Session
Example
>>> requests_cache.install_cache('demo_cache')
Accepts all the same parameters as
CachedSession
. Additional parameters:- Parameters
session_factory (
Type
[Session
]) – Session class to use. It must inherit from eitherCachedSession
orCacheMixin
cache_name (
str
) –expire_after (
Union
[None
,int
,float
,str
,datetime
,timedelta
]) –urls_expire_after (
Optional
[Dict
[str
,Union
[None
,int
,float
,str
,datetime
,timedelta
]]]) –stale_if_error (
bool
) –
- requests_cache.patcher.is_installed()[source]#
Indicate whether or not requests-cache is currently installed
- Return type
- requests_cache.patcher.remove_expired_responses(expire_after=None)[source]#
Remove expired responses from the cache, optionally with revalidation
- requests_cache.patcher.uninstall_cache()[source]#
Disable the cache by restoring the original
requests.Session