Skip to main content

Python SDK for AOps — prompt version management

Project description

aops

PyPI Python

Python SDK for AOps — prompt version management and agent observability platform.

  • Pull prompts from the AOps backend at runtime (any LLM SDK)
  • Trace runs — record which chains were called, in what order, and with what latency
  • Capture LLM I/O — log inputs and outputs per chain for full observability
  • Live updates — background polling reflects prompt edits without redeployment

Installation

pip install aops

With LangChain integration:

pip install "aops[langchain]" langchain-openai

Quick Start

1. Get an API key

In the AOps UI: Agent detail page → API Keys → New API Key

The key embeds the server host — no separate base_url needed.

2. Initialize and pull a prompt

import aops

aops.init(api_key="aops_...", agent="my-agent")

prompt = aops.pull("my-chain")   # returns str

3. Trace a run

Wrap your agent logic in aops.run() to record chain call order and latency:

with aops.run():
    classify_prompt = aops.pull("classify")       # traced
    category = call_llm(classify_prompt, user_input)

    respond_prompt = aops.pull(f"respond-{category}")   # traced
    return call_llm(respond_prompt, user_input)
# → posted to backend on exit, visible in the Flow tab

Capturing LLM Input / Output

Input is captured at pull() time by passing variables. Output is captured after the LLM responds via your chosen integration.

Step 1 — Pass variables to pull()

with aops.run():
    prompt = aops.pull("classify", variables={"inquiry": user_input})
    # ↑ input = rendered prompt (chain instructions + substituted user_input)

Step 2 — Capture output

Choose the integration that fits your stack.

Option A — LangChain / LCEL (AopsCallbackHandler)

from aops.langchain import AopsCallbackHandler
from langchain_openai import ChatOpenAI
from langchain_core.messages import SystemMessage, HumanMessage

handler = AopsCallbackHandler()
llm = ChatOpenAI(model="gpt-4o-mini", callbacks=[handler])

with aops.run():
    prompt = aops.pull("classify", variables={"inquiry": user_input})
    result = llm.invoke([SystemMessage(content=prompt), HumanMessage(content=user_input)])
    # output recorded automatically by handler

Option B — OpenAI SDK (wrap())

import openai
from aops import wrap

client = wrap(openai.OpenAI())

with aops.run():
    prompt = aops.pull("classify", variables={"inquiry": user_input})
    response = client.chat.completions.create(
        model="gpt-4o-mini",
        messages=[{"role": "system", "content": prompt}, {"role": "user", "content": user_input}],
    )
    # output recorded automatically by proxy

wrap() supports openai.OpenAI (sync) only. For async, use AopsCallbackHandler.

Option C — Any framework (@aops.trace decorator)

Captures the function's first argument as input and return value as output. Works with any LLM library.

@aops.trace("classify")
def classify(user_input: str) -> str:
    prompt = aops.pull("classify", variables={"inquiry": user_input})
    return call_any_llm(prompt, user_input)

with aops.run():
    result = classify(user_input)

Supports async def and class methods transparently.


Supported LLM SDKs

aops.pull() returns a plain str — works with any LLM SDK out of the box.

OpenAI

from openai import OpenAI
client = OpenAI()
response = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[{"role": "system", "content": aops.pull("my-chain")}, ...],
)

Anthropic

from anthropic import Anthropic
client = Anthropic()
message = client.messages.create(
    model="claude-haiku-4-5-20251001",
    max_tokens=1024,
    system=aops.pull("my-chain"),
    messages=[{"role": "user", "content": "Hello!"}],
)

LangChain (prompt as SystemMessagePromptTemplate)

from aops.langchain import pull   # returns SystemMessagePromptTemplate
from langchain_core.prompts import ChatPromptTemplate, HumanMessagePromptTemplate
from langchain_openai import ChatOpenAI

prompt = pull("my-chain")
chain = (
    ChatPromptTemplate.from_messages([
        prompt,
        HumanMessagePromptTemplate.from_template("{user_input}"),
    ])
    | ChatOpenAI(model="gpt-4o-mini")
)
result = chain.invoke({"user_input": "Hello!"})

Requirements


Examples

examples/
  openai_example.py       pull() + wrap() + OpenAI SDK
  anthropic_example.py    pull() + Anthropic SDK
  langchain_example.py    AopsCallbackHandler + @chain_prompt
  live_updates.py         background polling / live update detection

Documentation

Guide Description
Quickstart Step-by-step: from zero to first trace
Configuration aops.init(), API keys, environment variables
API Reference All public APIs: pull(), run(), wrap(), @trace, AopsCallbackHandler
Run Tracing aops.run(), I/O capture, concurrency
Live Updates Background polling, prompt refresh patterns
LangChain LCEL patterns, class-based chains, callback handler

Integration Quick References

Integration Guide
LangChain / LCEL docs/integrations/langchain.md
OpenAI SDK docs/integrations/openai.md
@aops.trace decorator docs/integrations/decorator.md

License

MIT

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

aops-0.7.0.tar.gz (17.9 kB view details)

Uploaded Source

Built Distribution

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

aops-0.7.0-py3-none-any.whl (20.7 kB view details)

Uploaded Python 3

File details

Details for the file aops-0.7.0.tar.gz.

File metadata

  • Download URL: aops-0.7.0.tar.gz
  • Upload date:
  • Size: 17.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for aops-0.7.0.tar.gz
Algorithm Hash digest
SHA256 0f617729f0f071ba88bf1e1a0edb9d22eac993d26e25ff1026fbf5f61ebd1a17
MD5 5c2211f049821ba5e2c31c8e3df78c2b
BLAKE2b-256 939a8e1f1a7ce7b6fd4c3be7c7f3b3034c3482729600958b494febc677555cab

See more details on using hashes here.

Provenance

The following attestation bundles were made for aops-0.7.0.tar.gz:

Publisher: release.yml on cow-coding/aops-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file aops-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: aops-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 20.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for aops-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 736352fe48dd2c33d1a7180b7cec4940fdd13f8a71d6633fb23595a8a6445bf9
MD5 dc71633e183e7905fa10c927bca0ecf1
BLAKE2b-256 dcd6b46e4bc56295b29d8b61cfc7c40f98488d035e0a552071bd1d1366149638

See more details on using hashes here.

Provenance

The following attestation bundles were made for aops-0.7.0-py3-none-any.whl:

Publisher: release.yml on cow-coding/aops-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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