Official Python client for the HyperCache API.
Project description
hypercache (Python SDK)
Python client for the HyperCache API. Zero runtime dependencies (stdlib only).
Install
pip install hypercache-kv
export HYPERCACHE_KEY=hck_...
Get a key at hypercache.ai.
Pipeline
Cache, records, and stats in one context:
from hypercache.workflows import Pipeline
with Pipeline("my_pipeline") as p:
answer, was_hit = p.cached(
label="gpt_call",
input_bytes=prompt.encode("utf-8"),
compute=lambda: call_openai(prompt),
)
p.record("output", answer.encode("utf-8"))
print(f"{p.report.n_hits} hits / {p.report.n_misses} misses")
Cache an expensive call
import hypercache
result = hypercache.cache_lookup(b"some input bytes")
if result.hit:
print(result.value)
else:
hypercache.cache_put(result.fingerprint_hex, b"my expensive output", ttl=3600)
results = hypercache.cache_lookup_batch([b"in 1", b"in 2", b"in 3"])
Wrap your LLM client
from openai import OpenAI
from hypercache.workflows import wrap_openai
client = wrap_openai(OpenAI())
resp = client.chat.completions.create(model="gpt-4o-mini", messages=[...])
wrap_anthropic does the same for the Anthropic SDK.
Records
import hypercache
fp = hypercache.fingerprint(b"any bytes")
print(fp.record_hex)
Link records to a prior one:
from hypercache.workflows import audit_chain
with audit_chain() as chain:
r1 = chain.fingerprint(input_bytes)
r2 = chain.fingerprint(model_output)
r3 = chain.fingerprint(reviewer_note)
License
MIT. See LICENSE.
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
hypercache_kv-0.1.2.tar.gz
(18.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 hypercache_kv-0.1.2.tar.gz.
File metadata
- Download URL: hypercache_kv-0.1.2.tar.gz
- Upload date:
- Size: 18.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
980a22c4cee1c912bbcbfb576d592ab54885f4df78d4c76b7ef3aa5ecaf0fdc4
|
|
| MD5 |
38a76c92e29e4c994e9405c9116431fb
|
|
| BLAKE2b-256 |
c28798bd1bdadddd3380e3eeb572e8a8ff63c66b1f48d3f5d233f828e680d2b9
|
File details
Details for the file hypercache_kv-0.1.2-py3-none-any.whl.
File metadata
- Download URL: hypercache_kv-0.1.2-py3-none-any.whl
- Upload date:
- Size: 18.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
825ebe7505516cb61a008eff1cab41fa350917c976d4135f3b30fdbca63e278d
|
|
| MD5 |
86e715b366f1505177501dc92ffe7c64
|
|
| BLAKE2b-256 |
f5352feb13d73fb782f0f63603076128da382299e743d703836e5dfd99a91777
|