Filesystem-cached niquests sessions.
Project description
niquests-cache
Filesystem-cached niquests sessions.
Installation
pip install niquests-cache
Example usage
The cached_session() helper returns a CachedSession or CachedAsyncSession whose cache root
is platformdirs.user_cache_path(app_name, appauthor=False) / 'http'. If you omit app_name,
niquests-cache is used. Only successful GET and HEAD responses are written to disk; the
default time-to-live is 10 minutes (expire_after= on the helper, or per-request—see below).
Sync helper (default app name and TTL):
from niquests_cache import cached_session
session = cached_session()
response = session.get('https://httpbin.org/get')
response.raise_for_status()
Custom application name for user_cache_path (same http subdirectory):
from niquests_cache import cached_session
session = cached_session(app_name='my-application')
response = session.get('https://httpbin.org/get')
response.raise_for_status()
Plain niquests session with no filesystem cache:
from niquests_cache import cached_session
session = cached_session(no_cache=True)
Construct CachedSession when you need an explicit directory or TTL:
from datetime import timedelta
from pathlib import Path
from niquests_cache import CachedSession
cache = Path('.cache') / 'http'
with CachedSession(cache_dir=cache, expire_after=timedelta(hours=1)) as session:
response = session.get('https://httpbin.org/get')
response.raise_for_status()
Async helper (use an async context manager):
import asyncio
from datetime import timedelta
from niquests_cache import cached_session
async def main() -> None:
session = cached_session(aio=True, expire_after=timedelta(minutes=30))
async with session:
response = await session.get('https://httpbin.org/get')
response.raise_for_status()
asyncio.run(main())
Or construct CachedAsyncSession directly:
import asyncio
from datetime import timedelta
from pathlib import Path
from niquests_cache import CachedAsyncSession
async def main() -> None:
cache = Path('.cache') / 'http'
async with CachedAsyncSession(cache_dir=cache, expire_after=timedelta(hours=1)) as session:
response = await session.get('https://httpbin.org/get')
response.raise_for_status()
asyncio.run(main())
To bypass the cache for a single request, pass expire_after=0 to request (that GET or
HEAD is not served from or written to the cache).
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file niquests_cache-0.0.2.tar.gz.
File metadata
- Download URL: niquests_cache-0.0.2.tar.gz
- Upload date:
- Size: 10.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c36b0ccffb6ed6cbf5be4ac6bf2d777a443a55e5c19635e0d941867a9a4e3a59
|
|
| MD5 |
ee9d67394def57f4ecd0602540d6b9e1
|
|
| BLAKE2b-256 |
d6f538d21b3eec6ad557adde46efbae3b31aaf879bb4c27867ccec8d9b57644f
|
Provenance
The following attestation bundles were made for niquests_cache-0.0.2.tar.gz:
Publisher:
publish.yml on Tatsh/niquests-cache
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
niquests_cache-0.0.2.tar.gz -
Subject digest:
c36b0ccffb6ed6cbf5be4ac6bf2d777a443a55e5c19635e0d941867a9a4e3a59 - Sigstore transparency entry: 1280440117
- Sigstore integration time:
-
Permalink:
Tatsh/niquests-cache@2c64cc34ec461e89868c899c03692a0bf439fcc7 -
Branch / Tag:
refs/tags/v0.0.2 - Owner: https://github.com/Tatsh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2c64cc34ec461e89868c899c03692a0bf439fcc7 -
Trigger Event:
push
-
Statement type:
File details
Details for the file niquests_cache-0.0.2-py3-none-any.whl.
File metadata
- Download URL: niquests_cache-0.0.2-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
53d96a66e86c20cf67c6bd1e446670a2aa1d182b43bb69eaa963f02ed1c83859
|
|
| MD5 |
f2cd5b489a5626bfb3241d662af424fc
|
|
| BLAKE2b-256 |
7e32b4a6ac8c670767026a1edeeaf61411e52d6c7fc6ecbf3259c398cb7992cd
|
Provenance
The following attestation bundles were made for niquests_cache-0.0.2-py3-none-any.whl:
Publisher:
publish.yml on Tatsh/niquests-cache
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
niquests_cache-0.0.2-py3-none-any.whl -
Subject digest:
53d96a66e86c20cf67c6bd1e446670a2aa1d182b43bb69eaa963f02ed1c83859 - Sigstore transparency entry: 1280440126
- Sigstore integration time:
-
Permalink:
Tatsh/niquests-cache@2c64cc34ec461e89868c899c03692a0bf439fcc7 -
Branch / Tag:
refs/tags/v0.0.2 - Owner: https://github.com/Tatsh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2c64cc34ec461e89868c899c03692a0bf439fcc7 -
Trigger Event:
push
-
Statement type: