Skip to main content

Coherent client-side caching for PyMongo

PyPI Python Coverage Typing

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.

Illustrative read latency on a logarithmic scale: direct local MongoDB read, 120 microseconds; direct Atlas M0 read, 79.4 milliseconds; cached read in either deployment, about 61 microseconds.

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.6.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 client-query-cache 0.6.0
File Size Uploaded
client_query_cache-0.6.0.tar.gz 45.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for client-query-cache 0.6.0
File Interpreter ABI Platform
client_query_cache-0.6.0-py3-none-any.whl Python 3 none any Details

Total release size: 109.5 kB

Release files / client_query_cache-0.6.0.tar.gz

Download URL client_query_cache-0.6.0.tar.gz
Size 45.2 kB
Tags Source
SHA-256 checksum
How to use checksums
f80cdc3391350ae6f9cbba5998935db394ad655160922ade88a905a2acbd2f1b
BLAKE2b-256 checksum
How to use checksums
fc4d1f5a359b93f1d980d1618542b40a3a3b8fdc96b2dd4b66d12bedf6b2e7d6
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 9, 2026.

Transparency log

Release files / client_query_cache-0.6.0-py3-none-any.whl

Download URL client_query_cache-0.6.0-py3-none-any.whl
Size 64.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4597e7cbf88bf5be1a07c1f02173dacdafecd2c0867a6c413079090f12ba895b
BLAKE2b-256 checksum
How to use checksums
fe304e93a7c6fc274707a585570329dd7edf2655246398a8d8a8054c901d8177
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 9, 2026.

Transparency log

Release history Release notifications | RSS feed

0.8.0

1 release file

0.7.0

2 release files

This release

0.6.0 This release

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

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