Skip to main content

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.2

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

API

  • alias_sha(model, content_type, url)
  • BASETEN_MM_HASH_HEADER
  • MMCacheClient.alias_sha(model=..., content_type=..., url=...)
  • MMCacheClient.resolve(...)
  • 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

Project details


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.2.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mm_cache_client-0.0.2-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file mm_cache_client-0.0.2.tar.gz.

File metadata

  • Download URL: mm_cache_client-0.0.2.tar.gz
  • Upload date:
  • Size: 5.4 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

Hashes for mm_cache_client-0.0.2.tar.gz
Algorithm Hash digest
SHA256 dc78543767b8ee4b04abdb18ce9deaeac6626e58cdcc4570e3f74a2783081e62
MD5 3cdc13e0760f7bb24b136fdbdb610a3e
BLAKE2b-256 165a701ea7243da43319abe8da6569f35524e6faca06e5abcc6569fac74d99f8

See more details on using hashes here.

File details

Details for the file mm_cache_client-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: mm_cache_client-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 4.0 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

Hashes for mm_cache_client-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 99a2777f2c12eef4cc1b47cfb44073cd2f747e99c8bb8f20603b070ffb42b784
MD5 eedda3cef0991af73cf131d17c5d3502
BLAKE2b-256 9e95382f56b16f77d39b565f24641bfafa045ad358a75d116ad9b1458ff3559c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page