Skip to main content

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_HEADER
  • MMCacheClient.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.py
  • examples/encoder_integration.py

Metadata

Release files for mm-cache-client 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mm-cache-client 0.0.3
File Size Uploaded
mm_cache_client-0.0.3.tar.gz 6.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mm-cache-client 0.0.3
File Interpreter ABI Platform
mm_cache_client-0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 10.3 kB

Release files / mm_cache_client-0.0.3.tar.gz

Download URL mm_cache_client-0.0.3.tar.gz
Size 6.1 kB
Tags Source
SHA-256 checksum
How to use checksums
7c89fc3042d2d20caaa016a9954a152e13a5a2840b74dbf2406ae951d6b2c24f
BLAKE2b-256 checksum
How to use checksums
c8690498fe08f849934b6f4f49bbec23c62b2982eca73612e200bf19999e2840
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release files / mm_cache_client-0.0.3-py3-none-any.whl

Download URL mm_cache_client-0.0.3-py3-none-any.whl
Size 4.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1a3e9f121506e5989a249e5dd3fab48360835878bec2d79322f4dd6ada6fc0c0
BLAKE2b-256 checksum
How to use checksums
398c0dfa442b9a24673f55f61cd38b35d26890a1549e2ecf8f3cd50f9744a85a
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files

0.0.2

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