Skip to main content

Anyway Software Development Kit (SDK) for Python

Project description

anyway-sdk

Anyway's Python SDK allows you to easily start monitoring and debugging your LLM execution. Tracing is done in a non-intrusive way, built on top of OpenTelemetry. You can choose to export the traces to your existing observability stack.

Installation

pip install anyway-sdk

Quick Start

from anyway.sdk import Traceloop
from anyway.sdk.decorators import workflow, task

Traceloop.init(app_name="joke_generation_service")

@workflow(name="joke_creation")
def create_joke():
    completion = openai.chat.completions.create(
        model="gpt-3.5-turbo",
        messages=[{"role": "user", "content": "Tell me a joke about opentelemetry"}],
    )
    return completion.choices[0].message.content

Configuration

Authentication

Choose one of the following methods to set your API key:

Option 1: Environment Variable

export TRACELOOP_HEADERS="Authorization=Bearer%20<your-api-key>"

Note: The space between Bearer and the key must be URL-encoded as %20.

Example:

export TRACELOOP_HEADERS="Authorization=Bearer%20sk_test_mncd5s5tQQJLuLNhRoXcYuNuptoOPuAY"

Then initialize the SDK:

from anyway.sdk import Traceloop

Traceloop.init(app_name="my_app")

Option 2: Pass Headers Directly

from anyway.sdk import Traceloop

Traceloop.init(
    app_name="my_app",
    headers={"Authorization": "Bearer <your-api-key>"}
)

Decorators

The SDK provides @workflow and @task decorators to organize and trace your LLM operations.

Import

from anyway.sdk.decorators import workflow, task

Parameters

Both decorators accept the same parameters:

Parameter Type Description
name Optional[str] Custom name for the span. If not provided, defaults to the function name.

@workflow

Use @workflow to define high-level operations that orchestrate multiple tasks.

@workflow(name="document_processor")
def process_document(text: str):
    summary = summarize_text(text)
    keywords = extract_keywords(text)
    return {"summary": summary, "keywords": keywords}

@task

Use @task to define individual units of work within a workflow.

@task(name="text_summarizer")
def summarize_text(text: str):
    completion = openai.chat.completions.create(
        model="gpt-3.5-turbo",
        messages=[{"role": "user", "content": f"Summarize: {text}"}],
    )
    return completion.choices[0].message.content

@task(name="keyword_extractor")
def extract_keywords(text: str):
    completion = openai.chat.completions.create(
        model="gpt-3.5-turbo",
        messages=[{"role": "user", "content": f"Extract keywords from: {text}"}],
    )
    return completion.choices[0].message.content

Nested Workflows and Tasks

Workflows can call tasks, and tasks can call other tasks to create a trace hierarchy:

from anyway.sdk import Traceloop
from anyway.sdk.decorators import workflow, task

Traceloop.init(app_name="content_pipeline")

@task(name="generate_content")
def generate_content(topic: str):
    completion = openai.chat.completions.create(
        model="gpt-3.5-turbo",
        messages=[{"role": "user", "content": f"Write about: {topic}"}],
    )
    return completion.choices[0].message.content

@task(name="review_content")
def review_content(content: str):
    completion = openai.chat.completions.create(
        model="gpt-3.5-turbo",
        messages=[{"role": "user", "content": f"Review this content: {content}"}],
    )
    return completion.choices[0].message.content

@workflow(name="content_pipeline")
def create_content(topic: str):
    content = generate_content(topic)
    reviewed = review_content(content)
    return reviewed

Async Support

Both decorators work seamlessly with async functions:

@task(name="async_summarizer")
async def summarize_text(text: str):
    completion = await async_openai_client.chat.completions.create(
        model="gpt-3.5-turbo",
        messages=[{"role": "user", "content": f"Summarize: {text}"}],
    )
    return completion.choices[0].message.content

@workflow(name="async_pipeline")
async def process_async(text: str):
    return await summarize_text(text)

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

anyway_sdk-0.0.3.tar.gz (53.0 kB view details)

Uploaded Source

Built Distribution

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

anyway_sdk-0.0.3-py3-none-any.whl (72.2 kB view details)

Uploaded Python 3

File details

Details for the file anyway_sdk-0.0.3.tar.gz.

File metadata

  • Download URL: anyway_sdk-0.0.3.tar.gz
  • Upload date:
  • Size: 53.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.14.2 Darwin/24.6.0

File hashes

Hashes for anyway_sdk-0.0.3.tar.gz
Algorithm Hash digest
SHA256 263ac5dbeaca4a4898d499c294b8934877051cf4b528bf6b0e7b14a8b2a763ac
MD5 e6f2bcfb12460c00917be38b96a22cd9
BLAKE2b-256 b9ba0d261247902cb532af1120c8a1eeac7de3d2d1931aa8680dec0418e2d8df

See more details on using hashes here.

File details

Details for the file anyway_sdk-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: anyway_sdk-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 72.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.14.2 Darwin/24.6.0

File hashes

Hashes for anyway_sdk-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 60650a8bf634e08fca6d98c1e37c25eb2a0789f6aac662773c3169f457760a3c
MD5 80808e248d8c4f1bdbd968a93bee49ca
BLAKE2b-256 76099421784a72f144205d49835b79c67e6f892f8fd0e2e92b333b33cef86f5d

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