Requests-Cache
Summary
requests-cache is a transparent, persistent HTTP cache for the python requests library. It's a convenient tool to use with web scraping, consuming REST APIs, slow or rate-limited sites, or any other scenario in which you're making lots of requests that are expensive and/or likely to be sent more than once.
See full project documentation at: https://requests-cache.readthedocs.io
Features
- Ease of use: Use as a drop-in replacement
for
requests.Session, or install globally to add caching to allrequestsfunctions - Customization: Works out of the box with zero config, but with plenty of options available for customizing cache expiration and other behavior
- Persistence: Includes several storage backends: SQLite, Redis, MongoDB, GridFS, DynamoDB, and filesystem.
- Compatibility: Can be used alongside other popular libraries based on requests
Quickstart
First, install with pip:
pip install requests-cache
Next, use requests_cache.CachedSession to send and cache requests. To quickly demonstrate how to use it:
This takes ~1 minute:
import requests
session = requests.Session()
for i in range(60):
session.get('http://httpbin.org/delay/1')
This takes ~1 second:
import requests_cache
session = requests_cache.CachedSession('demo_cache')
for i in range(60):
session.get('http://httpbin.org/delay/1')
The URL in this example adds a delay of 1 second, simulating a slow or rate-limited website.
With caching, the response will be fetched once, saved to demo_cache.sqlite, and subsequent
requests will return the cached response near-instantly.
If you don't want to manage a session object, requests-cache can also be installed globally:
requests_cache.install_cache('demo_cache')
requests.get('http://httpbin.org/delay/1')
Next Steps
To find out more about what you can do with requests-cache, see:
- The User Guide and Advanced Usage sections
- A working example at Real Python: Caching External API Requests
- More examples in the examples/ folder
Metadata
Release files for requests-cache 0.7.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| requests-cache-0.7.4.tar.gz | 1.2 MB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| requests_cache-0.7.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 1.3 MB
Release files / requests-cache-0.7.4.tar.gz
| Download URL | requests-cache-0.7.4.tar.gz |
|---|---|
| Size | 1.2 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4786190991b5f9e8ecfa97a1a6fd02475486e522a6d62f4bea53c32a7c1172c9
|
|
BLAKE2b-256 checksum How to use checksums |
1933f7a13f40ef2a607406ce153f34946589aa0fb83fc8ac23623ff83af50548
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.2.0a2 CPython/3.9.6 Linux/5.4.0-1055-azure
|
Release files / requests_cache-0.7.4-py3-none-any.whl
| Download URL | requests_cache-0.7.4-py3-none-any.whl |
|---|---|
| Size | 38.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ca7b7d138033dffb07922856a55d51934497024f1d5b8425acbcfa58ee97269f
|
|
BLAKE2b-256 checksum How to use checksums |
861975c6caf0cb277cb5dc135c9d7205dc7ca9fbd3e9a03cc4b5591b6e7ea5d1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.2.0a2 CPython/3.9.6 Linux/5.4.0-1055-azure
|