Python SDK
Cloudmind Python SDK reference: decorators, context managers, async support and prompt fetching.
pip install cloudmind
Monitoring wrappers
from openai import OpenAI
from cloudmind.openai import monitor_openai
client = monitor_openai(OpenAI())
Decorator
from cloudmind import trace
@trace(name="answer-question")
def answer(question: str) -> str:
chunks = retrieve(question)
return generate(question, chunks)
The decorator works on both sync and async functions.
Context manager
from cloudmind import cloudmind
with cloudmind.trace(name="answer-question", user_id="u_123") as t:
with t.span(name="retrieve", kind="retrieval") as span:
docs = store.search(question, k=5)
span.record(query=question, chunks=docs)
answer = generate(question, docs)
Prompts
prompt = cloudmind.prompts.get("support-summary", label="production")
messages = prompt.render(ticket=ticket.body, tone="concise")
Async
Every method has an async equivalent prefixed with a:
await cloudmind.atrace(...)
await cloudmind.aflush()
Flushing
cloudmind.flush()
Call before exiting a Lambda handler or a short-lived script.