Tiny aiohttp client for the mm-cache distributed cache service
Project description
mm-cache-client
mm-cache-client is a tiny async Python client for the mm-cache service.
Install
pip install mm-cache-client==0.0.3
Usage
from mm_cache_client import MMCacheClient, MMCacheConfig
async with MMCacheClient(MMCacheConfig(base_url="http://mm-cache:8080")) as cache:
hit = await cache.resolve(
model="moonshotai/Kimi-K2.5",
content_type="image_url",
url="https://example.com/cat.png",
)
if hit is not None:
mm_hash = hit.mm_hash
mm_kwargs = hit.mm_kwargs
Plugin fast path:
sha = MMCacheClient.alias_sha(
model=model_id,
content_type="image_url",
url=url,
)
hit = await cache.resolve_sha(model=model_id, sha=sha)
if hit is not None:
return hit.mm_hash, hit.mm_kwargs
Presigned URL churn:
hit = await cache.get_payload(model=model_name, mm_hash=mm_hash)
if hit is not None:
mm_kwargs = hit.mm_kwargs
Resolve or compute on miss:
from mm_cache_client import CacheHit
async def encode() -> CacheHit:
return CacheHit(mm_hash=mm_hash, mm_kwargs=mm_kwargs)
hit = await cache.resolve_or_call(
model=model_name,
content_type="image_url",
url=url,
on_miss=encode,
)
API
alias_sha(model, content_type, url)BASETEN_MM_HASH_HEADERMMCacheClient.alias_sha(model=..., content_type=..., url=...)MMCacheClient.resolve(...)MMCacheClient.resolve_or_call(...)MMCacheClient.resolve_sha(...)MMCacheClient.resolve_alias(...)MMCacheClient.get_payload(...)MMCacheClient.put_resolve(...)MMCacheClient.put_sha(...)MMCacheClient.put_payload(...)
Integration patterns
image_encoder_plugin:
sha = MMCacheClient.alias_sha(model=model_id, content_type="image_url", url=url)
hit = await cache.resolve_sha(model=model_id, sha=sha)
if hit is not None:
return hit.mm_hash, hit.mm_kwargs
Encoder backend:
hit = await cache.resolve(model=model_id, content_type="image_url", url=url)
if hit is not None:
return hit.mm_hash, hit.mm_kwargs
hit = await cache.get_payload(model=model_id, mm_hash=mm_hash)
if hit is not None:
return hit.mm_hash, hit.mm_kwargs
See:
examples/plugin_integration.pyexamples/encoder_integration.py
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
mm_cache_client-0.0.3.tar.gz
(6.1 kB
view details)
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 mm_cache_client-0.0.3.tar.gz.
File metadata
- Download URL: mm_cache_client-0.0.3.tar.gz
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.8 {"installer":{"name":"uv","version":"0.10.8","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":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7c89fc3042d2d20caaa016a9954a152e13a5a2840b74dbf2406ae951d6b2c24f
|
|
| MD5 |
c9e73d3f578ce0348c3a6de70ae1662b
|
|
| BLAKE2b-256 |
c8690498fe08f849934b6f4f49bbec23c62b2982eca73612e200bf19999e2840
|
File details
Details for the file mm_cache_client-0.0.3-py3-none-any.whl.
File metadata
- Download URL: mm_cache_client-0.0.3-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.8 {"installer":{"name":"uv","version":"0.10.8","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":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1a3e9f121506e5989a249e5dd3fab48360835878bec2d79322f4dd6ada6fc0c0
|
|
| MD5 |
61f9d98f4f7e8bede479ce99da70dac3
|
|
| BLAKE2b-256 |
398c0dfa442b9a24673f55f61cd38b35d26890a1549e2ecf8f3cd50f9744a85a
|