Skip to content

The instructions below are rendered from the canonical example catalogue source. Follow the hosted integration guides in the catalogue to study each application or adapter and its complete program.

Examples

Each example is a complete program that adds client-query-cache to a MongoDB-backed library or an application with explicit MongoDB storage. Writes go to PyMongo, and supported reads use cached views. Each run prints cache statistics as evidence that repeated reads came from the cache and that a later write invalidated the cached entry, and exits with an error if either did not happen.

The examples demonstrate integrations; they do not recommend caching every read. Authorization policies and Celery task state can lag a write until invalidation arrives; see the py-abac guide and consistency limits. The FastAPI catalogue guide shows an application that reads update responses directly, and --serve runs it under Uvicorn with several worker processes.

Prerequisites

  • A MongoDB 8.0+ replica set. The repository's docker-compose.yaml starts one on localhost:27017, which the examples use by default. To use another deployment, set MONGODB_URI to its connection string.
  • uv. Each example declares its own dependencies, and uv installs them into a separate, cached environment the first time you run it.

Each example deletes its own database when it starts, for example client_query_cache_example_requests_cache, so do not point MONGODB_URI at a deployment where that database holds data you need.

Run the examples

Run each command from the repository checkout. The filenames below link to executable source; the hosted guides explain the integrations.

Example Library or framework Run
requests_cache_example.py requests-cache uv run examples/requests_cache_example.py
fastapi_catalogue_example.py FastAPI uv run examples/fastapi_catalogue_example.py
fastapi_minimal_example.py FastAPI uv run examples/fastapi_minimal_example.py
celery_example.py Celery uv run examples/celery_example.py
py_abac_example.py py-abac uv run examples/py_abac_example.py
aiohttp_client_cache_example.py aiohttp-client-cache uv run examples/aiohttp_client_cache_example.py
eve_example.py Eve uv run examples/eve_example.py

Hosted integration guides