Skip to main content

cachepot

PyPI - Python Version PyPI PyPI - Downloads Lint and Test Python Coverage License

Yet another Python cache library. This has Python 3 typing hints.

Installation

$ pip install cachepot

Usage

>>> from cachepot import CacheStore, FileSystemCacheBackend
>>> from cachepot.serializer.pickle import PickleSerializer
>>> store = CacheStore(
...     namespace='testing',
...     key_serializer=PickleSerializer(),
...     value_serializer=PickleSerializer(),
...     backend=FileSystemCacheBackend('/tmp'),
...     default_expire_seconds=3600,
... )
>>> store.put({'some': 'key'}, {'some': 'value'})
>>> store.get({'some': 'key'})
{'some': 'value'}
>>> store.put({'some': 'short expiring key'}, {'some': 'value'}, expire_seconds=10)
>>> store.delete_expired()
0

delete_expired() returns the number of entries removed when the backend can observe that count. Redis handles TTL expiry server-side, so its backend returns None when the deleted-entry count is unknown. SQLite also opportunistically removes expired rows during later writes, while delete_expired() remains available when you want to force a cleanup cycle.

Security note: PickleSerializer uses Python's pickle module, which can execute arbitrary code during deserialization. The serializer is intentionally not exported from cachepot's top-level namespace. Import it explicitly from cachepot.serializer.pickle only when the cache backend storage is fully under your control and trusted. For untrusted environments, prefer JSONSerializer instead.

Proxy method

result = store.proxy(some_func)(some_args, cache_key=some_arg)

is the equivalent of

result = store.get(some_arg)
if result is None:
    result = some_func(some_args)
    store.put(some_arg, result)

In short, this works as proxy. This helps to make codes straight forward. cache_key and expire_seconds are keyword-only arguments of the proxy itself, not of the proxied function. store.proxy(...) raises TypeError at proxy creation time if the proxied function declares a parameter named cache_key or expire_seconds, because those names are reserved for the proxy.

When a proxied cache write fails, cachepot keeps returning the computed result, emits a CachepotWarning, logs the failure on the cachepot.store logger, and increments store.cache_write_failures. This lets applications forward failures to their existing logging or metrics pipeline without giving up graceful degradation.

Core idea

Serializers convert python objects into bytes. Backends save/load bytes. So serializers and backends are independent. CacheStore is the facade of them.

Backends now enforce a finite per-entry size contract by default: max_entry_bytes=8 * 1024 * 1024 (8 MiB). Entries larger than that are rejected on save(), and load() checks the backend-side size before materializing the payload into process memory. You can override the limit per backend instance when your application has a different budget.

  • Python3 typing supports
  • namespaces
  • Proxy method
  • Expired entry cleanup

Features

Serializers

And more serializers you can define.

Backends

Of course you can define own backend.

Development

This repository uses lefthook to run the same checks as CI locally, so problems surface before they reach CI.

# Install dependencies
uv sync

# Install the Git hooks (once; requires lefthook on your PATH)
lefthook install

Once installed, the hooks run automatically:

  • pre-commit: uv run poe check
  • pre-push: uv run poe check and uv run poe test

You can also run the checks manually:

uv run poe check
uv run poe test

CI still runs the full matrix (see .github/workflows/); the hooks only bring that feedback earlier on your machine.

LICENSE

The 3-Clause BSD License. See also LICENSE file.

Metadata

Release files for cachepot 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cachepot 0.5.0
File Size Uploaded Provenance Actions
cachepot-0.5.0.tar.gz 105.5 kB With provenance Details for cachepot-0.5.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cachepot 0.5.0
File Interpreter ABI Platform Actions
cachepot-0.5.0-py3-none-any.whl Python 3 none any Details for cachepot-0.5.0-py3-none-any.whl

Total release size: 125.3 kB

Release files / cachepot-0.5.0.tar.gz

Download URL cachepot-0.5.0.tar.gz
Size 105.5 kB
Tags Source
SHA-256 checksum
How to use checksums
6e5126bdf1e6aa868d22c7928b02101e091d633f0b8df24aaaaad3aecc658e73
BLAKE2b-256 checksum
How to use checksums
8c2483445ed21dce127293734c6f4a15fedaf1738c1bb1f099b8416ce70706f5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 27, 2026.

Transparency log

Release files / cachepot-0.5.0-py3-none-any.whl

Download URL cachepot-0.5.0-py3-none-any.whl
Size 19.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
60bffd171282d2438fb64e1ad3e6d6e5c5d00e81540de001eeba1d1b7a73184e
BLAKE2b-256 checksum
How to use checksums
03a7e26b9bd268364121702b0dd49b05fb9a36d6b2ff5973c217f366c83a207b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 27, 2026.

Transparency log

Security for cachepot 0.5.0

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for cachepot-0.5.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 27, 2026.

Transparency log

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page