Skip to main content

memoturn Python SDK — tracing, @observe, OpenAI wrapper, prompts.

Project description

memoturn Python SDK

Tracing, prompts, and the OpenAI wrapper for memoturn. Stdlib-only (no required dependencies).

pip install memoturn        # or: uv add memoturn

Trace with the decorator

from memoturn import Memoturn, configure, observe

configure(Memoturn(base_url="http://localhost:3001", public_key="pk-...", secret_key="sk-..."))

@observe()
def retrieve(q): ...

@observe(as_type="generation")
def answer(q, docs): ...

@observe(name="rag-pipeline")
def rag(q):
    return answer(q, retrieve(q))   # nested spans under one trace

The outermost @observe opens a trace; nested calls become child spans (a waterfall in the console). Env vars MEMOTURN_BASE_URL / MEMOTURN_PUBLIC_KEY / MEMOTURN_SECRET_KEY are used when not passed explicitly.

Low-level API

mt = Memoturn()
trace = mt.trace(name="chat", user_id="u1")
gen = trace.generation(name="answer", model="claude-sonnet-4-6", input=messages)
gen.end(output=reply, usage={"promptTokens": 100, "completionTokens": 20})
trace.score("user-feedback", value=1, comment="helpful")
mt.shutdown()  # flush

OpenAI wrapper

from openai import OpenAI
from memoturn import wrap_openai

client = wrap_openai(OpenAI())
client.chat.completions.create(model="gpt-4o-mini", messages=[...])  # recorded automatically

Prompts

from memoturn import get_prompt, compile_prompt

prompt = get_prompt("support-reply", channel="production")
messages = compile_prompt(prompt, product="memoturn", question="How do I trace a call?")

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

memoturn-0.2.0.tar.gz (41.5 kB view details)

Uploaded Source

Built Distribution

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

memoturn-0.2.0-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file memoturn-0.2.0.tar.gz.

File metadata

  • Download URL: memoturn-0.2.0.tar.gz
  • Upload date:
  • Size: 41.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","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":true}

File hashes

Hashes for memoturn-0.2.0.tar.gz
Algorithm Hash digest
SHA256 a426216f7fb1906f3dde7bb5c8a9614f13aeeae648e6e1ac5ff29feeda25df18
MD5 72872296a5c8533fc755c565b705bd88
BLAKE2b-256 0de168f225b77fed8f29cb85e8fd607dadfc2ea3e2a531a9209e66ac76362488

See more details on using hashes here.

File details

Details for the file memoturn-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: memoturn-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","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":true}

File hashes

Hashes for memoturn-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 60dd7565cc31daed0c80323a42d7ea2fb229f42dcc72d42aa415fef16233c35b
MD5 b19485efb2c25814aa91f5bfda790287
BLAKE2b-256 8e946c7d86ed097bbd68dcc9c2cef6c372ddef65c88538b182dda116f7148d79

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