Coherent client-side caching for PyMongo
client-query-cache uses MongoDB change streams to keep cached reads coherent. It supports synchronous and asyncio applications without requiring a separate cache server.
Built for production: Designed for high-traffic, read-heavy applications, with cache hits served from memory to reduce latency and database load. Quality is backed by a 100% test-coverage requirement, real MongoDB integration and concurrency stress tests, and automated performance and memory regression checks.
Results vary by workload and deployment. Measurements and methodology.
Caching requires MongoDB 8.0+ on a replica set or sharded cluster. Reads on standalone servers and older MongoDB versions run through PyMongo without caching.
Invalidation is asynchronous: a cached read can return a preceding value until the write's change-stream event is processed. Use PyMongo directly when a read must immediately observe a preceding write.
Quick start
uv add client-query-cache
Or use pip install client-query-cache.
from pymongo import MongoClient
from client_query_cache import CacheManager
with (
MongoClient("mongodb://localhost:27017") as client,
CacheManager(client) as cache,
):
users = cache.get_cached_collection(client["my_database"]["users"])
users.find_one({"_id": "alice"}) # Reads from MongoDB.
users.find_one({"_id": "alice"}) # Repeated reads can use the cache.
References
Getting started · Benchmarks · Examples
MongoDB is a registered trademark of MongoDB, Inc. This project is independent and is not affiliated with or endorsed by MongoDB, Inc.
Metadata
Release files for client-query-cache 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| client_query_cache-0.5.0.tar.gz | 44.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| client_query_cache-0.5.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 108.6 kB
Release files / client_query_cache-0.5.0.tar.gz
| Download URL | client_query_cache-0.5.0.tar.gz |
|---|---|
| Size | 44.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
679763f5810b3b348fd2928b4d2d3f24a3a7925c0667982064695c52d4d0f787
|
|
BLAKE2b-256 checksum How to use checksums |
f318847770df1368b640068d717f5fd123a8dfb03e19abff1efc29655e0b7966
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 8, 2026.
Transparency logRelease files / client_query_cache-0.5.0-py3-none-any.whl
| Download URL | client_query_cache-0.5.0-py3-none-any.whl |
|---|---|
| Size | 63.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
49f7a43603ec793229bf8ede2277cc9da920f77a15fd8c1e7881b30d073ad2fe
|
|
BLAKE2b-256 checksum How to use checksums |
3426e8207bc7ddb238cdd3fd6c7938eae07e83553a00bbc795e1ce2299b9c6e4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 8, 2026.
Transparency log