SmartRequests
A lightweight wrapper around requests.Session that adds transparent disk caching with simple r / w / rw mode control and response condition validation.
Install
pip install smart_requests_dvxb
Standard vs Smart
Standard requests — fetches every time:
import requests
session = requests.Session()
resp = session.get("https://example.com/data.json")
print(resp.text) # hits network every single run
SmartRequests — fetches once, reads from disk after:
import requests
from SmartRequests import smart_session
session = smart_session(requests.Session())
resp = session.get(
"https://example.com/data.json",
mode="rw",
filepath="/cache/data.json",
)
print(resp.text) # network on first run, disk on every run after
That's the only change. Everything else (headers, cookies, params, data, json) works exactly as before.
Modes
| Mode | Behavior |
|---|---|
r |
Read from cache only — raises error if file missing |
w |
Always fetch from network, write result to disk |
rw |
Return cache if exists, otherwise fetch and store |
rb / wb / rwb |
Same as above but read/write raw bytes (images, PDFs) |
Condition Validation
Conditions are lambdas evaluated against the response before writing to disk. If any condition fails, the file is never written and a ValueError is raised — so you never cache a bad response.
Without SmartRequests — bad response silently saved:
resp = session.post(url, data=payload)
with open("result.html", "w") as f:
f.write(resp.text) # saves error page, captcha page, anything
With SmartRequests — only valid responses are cached:
resp = session.post(
url,
data=payload,
mode="w",
filepath="/cache/result.html",
conditions=[
lambda r: r.status_code == 200,
lambda r: len(r.content) > 500,
lambda r: "error" not in r.text,
lambda r: "captcha" not in r.text.lower(),
],
)
Full Parameter Reference
| Parameter | Type | Description |
|---|---|---|
mode |
str |
One of r, w, rw, rb, wb, rwb |
filepath |
str |
Absolute path to cache file — required when mode is set |
conditions |
list[callable] |
Lambdas evaluated against response before writing — raises ValueError on first failure |
Contact Developer
Dharmik Vadher — dharmik.vadher@xbyte.io
Metadata
Release files for smart-requests-dvxb 0.23
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| smart_requests_dvxb-0.23-cp312-cp312-win_amd64.whl | CPython 3.12 | CPython 3.12 | Windows x86-64 | Details for smart_requests_dvxb-0.23-cp312-cp312-win_amd64.whl |
Release files / smart_requests_dvxb-0.23-cp312-cp312-win_amd64.whl
| Download URL | smart_requests_dvxb-0.23-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 96.5 kB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
295019382297acbc50a900e59485c27a4a50a5820b8b1bd15eec5eb437025dde
|
|
BLAKE2b-256 checksum How to use checksums |
ed5829743b3f381c20c0da9971e4d2f0e0696cdef780f494bdf248fa0b5bcc1c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.6
|
Security for smart-requests-dvxb 0.23
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.