boto3-client-cache provides a concurrency-safe, bounded cache for boto3 clients with deterministic identity semantics.
Project description
boto3-client-cache
Description
boto3-client-cache provides a concurrency-safe, bounded cache for boto3 clients with deterministic identity semantics.
LRU and LFU eviction are supported.
Why this Exists
boto3 clients consume a large amount of memory. Many developers never notice this. At scale, however, the memory footprint of boto3 clients often becomes clear through manifold consequences. Client caching is an obvious choice for managing multiple clients at scale. There are, to my knowledge, no other open-source tools available which do what boto3-client-cache does.
Design
The most important but challenging design choice for client caching is selecting and enforcing a robust and standardized methodology for unique keys. boto3-client-cache hashes according to boto3 client signatures.
Setting and retrieving clients from the client cache therefore requires an explicit declaration of intention -- that is, the developer must explicitly pass client initialization parameters to a ClientCacheKey object in order to set or retrieve boto3 clients. This ensures setting and retrieving clients are unambiguous and deterministic operations. By locking the client cache, as boto3-client-cache does, race conditions are prevented, enabling developers to confidently employ the client cache at scale with predictable cache eviction behavior. Lastly, by designing the cache like a dict in the standard Python library, the cache is ergonomically familiar and thus easy to use.
These decisions reflect the core design goals of boto3-client-cache: safety at scale, deterministic behavior, ergonomic interfacing, and explicit identity.
Installation
pip install boto3-client-cache
Quickstart
Refer to the official documentation for additional information.
from boto3_client_cache import ClientCache, ClientCacheKey
import boto3
# create an LRU client cache with a maximum size of 30
cache = ClientCache(max_size=30)
# store boto3 client params in an object
kwargs = {"service_name": "s3", "region_name": "us-west-2"}
# create a cache key using those params
key = ClientCacheKey(**kwargs)
# assign a client
cache[key] = boto3.client(**kwargs)
# and retrieve that client using the key
s3_client = cache[key]
Error Semantics
Refer to the official documentation for additional information.
# raises ClientCacheExistsError b/c client(**kwargs) already exists
cache[key] = boto3.client(**kwargs)
# raises ClientCacheNotFoundError b/c the specific client was not cached
cache[ClientCacheKey(service_name="ec2", region_name="us-west-2")]
# returns None instead of raising ClientCacheNotFoundError
cache.get(ClientCacheKey(service_name="ec2", region_name="us-west-2"))
# raises ClientCacheError b/c the key is not a ClientCacheKey
cache["this is not a ClientCacheKey"]
# raises ClientCacheError b/c the object is not a client
cache[ClientCacheKey("s3")] = "this is not a boto3 client"
License
boto3-client-cache is licensed by the Apache Software License (2.0).
Contributing
Refer to the contributing guidelines for additional information on how to contribute to boto3-client-cache.
Special Thanks
Project details
Release history Release notifications | RSS feed
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 boto3_client_cache-1.0.0.tar.gz.
File metadata
- Download URL: boto3_client_cache-1.0.0.tar.gz
- Upload date:
- Size: 15.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7fd252dbbfc81079a149a777a2b7c54d963f365c779b5d52e885005a09e345e5
|
|
| MD5 |
5480e063ceebe335a08f9a8e5bbc2969
|
|
| BLAKE2b-256 |
ac42a147a9aa36bfaab7bb68c5c792a4251cc2b53b17139c35ac87954d22cec7
|
File details
Details for the file boto3_client_cache-1.0.0-py3-none-any.whl.
File metadata
- Download URL: boto3_client_cache-1.0.0-py3-none-any.whl
- Upload date:
- Size: 18.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ea4c93e40f40d888827ca926ef1bb6c5a8866b88a57c42a33b1269bccf418dd1
|
|
| MD5 |
8da60ab9d0b1950db57daac0fd0bb7bd
|
|
| BLAKE2b-256 |
33ab615f9b9c805358f06e806d5770af8e61ffabdf0d31277725193666934b17
|