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.6.0.tar.gz (16.5 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.6.0-py3-none-any.whl (19.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for aops-0.6.0.tar.gz
Algorithm Hash digest
SHA256 317161e05a6326039d69b244256979d577a3e4cd5e462c06bb49c25a5605f237
MD5 0a7fee93064a33c1b9c401ae31c2f51d
BLAKE2b-256 f3dbe461021f6bc9a736689463095a2f9070d078648ebb790796d32a18e63d20

See more details on using hashes here.

Provenance

The following attestation bundles were made for aops-0.6.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.6.0-py3-none-any.whl.

File metadata

  • Download URL: aops-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 19.3 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.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8461b2f675843738aed4bd0aab55786c7f366b12a61e793bf9fabd0f98583702
MD5 59300714ad9d5295007148933fc3768a
BLAKE2b-256 cb88cdbf36b02ce1c126e4adae6ae8a1e1139bfb8a70fa3331f1bc39f8d99f39

See more details on using hashes here.

Provenance

The following attestation bundles were made for aops-0.6.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