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.1.0.tar.gz (45.2 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.1.0-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: memoturn-0.1.0.tar.gz
  • Upload date:
  • Size: 45.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.24 {"installer":{"name":"uv","version":"0.11.24","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.1.0.tar.gz
Algorithm Hash digest
SHA256 2f39123bf786de87bfbfa3aa0b8a321575e325cee8547408bf74d1b30f127706
MD5 1e04ae471cc14bc10ee181ba0c38f2c2
BLAKE2b-256 9026c5a6687da7dcd0b985398243df7776d123f25837945d8ae087830c998d7b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: memoturn-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.24 {"installer":{"name":"uv","version":"0.11.24","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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c501ecc7f813760429e7b473add96262ec3ed7d31d96a720c7732a25242eabb3
MD5 b46f2eb86ede668a14e34a00dadbf2e9
BLAKE2b-256 8c65971f7303d2bc48713063f8e87f33014ea6234fdb62e393d1bb36944a2333

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