Skip to main content

Python SDK for Atheon

Project description

Codex: Python SDK for Atheon

The Atheon Codex Python library provides convenient access to the Atheon Gateway from any Python 3.11+ application. It includes type definitions for all request params and response fields, and offers both synchronous and asynchronous clients powered by httpx.

Installation

pip install atheon-codex

Quick Start

import os
import atheon
 
# Initialise once at application startup
atheon.init(os.environ["ATHEON_API_KEY"])
 
# Track a completed interaction — non-blocking, enqueues in the background
interaction_id = atheon.track(
    provider="openai",
    model_name="gpt-4o",
    input="How can I write blogs for my website?",
    output="Start by identifying your target audience...",
    tokens_input=18,
    tokens_output=120,
    finish_reason="stop",
    status_code=200,
)
 
# Pass interaction_id to your frontend: <atheon-container interaction-id="...">
print(interaction_id)
 
# Flush and stop the background queue before process exit
atheon.shutdown()

Note: Get your API key from the Atheon Gateway Dashboard under Project Settings. We recommend storing it in a .env file using python-dotenv rather than hardcoding it in source.


Usage

Initialisation

Call atheon.init() once at application startup. All subsequent calls share the global client automatically.

atheon.init(
    api_key=os.environ["ATHEON_API_KEY"],
    upload_size=10,        # events per HTTP batch (default 10)
    upload_interval=1.0,   # seconds between background flushes (default 1.0)
    max_queue_size=10_000, # max in-memory queue depth (default 10 000)
)

Streaming & Multi-Turn: begin() / finish()

Use begin() / finish() when the response spans time. Wall-clock latency is measured automatically.

interaction = atheon.begin(
    provider="anthropic",
    model_name="claude-sonnet-4-5",
    input="Summarise our Q3 report",
    properties={"agent": "rag-pipeline", "environment": "production"},
)
 
# ... stream response, call tools, run sub-agents ...
 
interaction.set_property("user_tier", "pro")  # enrich mid-flight
 
interaction_id = interaction.finish(
    output=final_text,
    tokens_input=80,
    tokens_output=220,
    finish_reason="stop",
    status_code=200,
)

Tool Tracking: @atheon.tool

Decorate any function (sync or async) to record its name, latency, and errors into the active interaction automatically — no explicit passing required.

@atheon.tool("vector-search")
def search(query: str) -> list[str]:
    return db.search(query)
 
@atheon.tool("reranker")
async def rerank(docs: list[str]) -> list[str]:
    return await model.rerank(docs)

@atheon.tool is a no-op if called outside an active begin() context — safe to use unconditionally.

Sub-Agent Tracking: @atheon.agent

Decorate LLM-backed sub-agent functions to nest their tool calls and token usage inside the root interaction. Everything ships in a single payload on finish().

@atheon.agent(
    "rag-pipeline",
    provider="anthropic",
    model_name="claude-haiku-4-5",
)
def rag_agent(query: str) -> str:
    chunks = search(query)
    response = llm.messages.create(...)
    atheon.set_result(
        tokens_input=response.usage.input_tokens,
        tokens_output=response.usage.output_tokens,
        finish_reason=response.stop_reason,
        status_code=response.status_code,
    )
    return response.content[0].text

Async Support

For async frameworks (FastAPI, Django async views, etc.), use the async API. async_track() and async_begin() are synchronous enqueues — call without await.

# FastAPI example
from contextlib import asynccontextmanager
from fastapi import FastAPI
 
@asynccontextmanager
async def lifespan(app: FastAPI):
    atheon.async_init(os.environ["ATHEON_API_KEY"])
    yield
    await atheon.async_shutdown()
 
app = FastAPI(lifespan=lifespan)
 
@app.post("/chat")
async def chat(req: ChatRequest):
    final_text = await llm.complete(req.message)
    interaction_id = atheon.async_track(   # no await
        provider="openai",
        model_name="gpt-4o",
        input=req.message,
        output=final_text,
        finish_reason="stop",
        status_code=200,
    )
    return {"reply": final_text, "interaction_id": str(interaction_id)}

Use either atheon.init() or atheon.async_init() — not both in the same process.

Direct Client Instantiation

The module-level helpers are recommended for most applications. For multiple isolated clients in the same process, instantiate directly:

from atheon import AtheonCodexClient, AsyncAtheonCodexClient
 
# Sync
with AtheonCodexClient(api_key=os.environ["ATHEON_API_KEY"]) as client:
    client.track(provider="openai", model_name="gpt-4o", input="...", output="...")
 
# Async
async with AsyncAtheonCodexClient(api_key=os.environ["ATHEON_API_KEY"]) as client:
    client.track(provider="openai", model_name="gpt-4o", input="...", output="...")

Links

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

atheon_codex-1.0.7.tar.gz (73.0 kB view details)

Uploaded Source

Built Distribution

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

atheon_codex-1.0.7-py3-none-any.whl (22.1 kB view details)

Uploaded Python 3

File details

Details for the file atheon_codex-1.0.7.tar.gz.

File metadata

  • Download URL: atheon_codex-1.0.7.tar.gz
  • Upload date:
  • Size: 73.0 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 atheon_codex-1.0.7.tar.gz
Algorithm Hash digest
SHA256 581247bedb637e3da162102fb21491342bd208235d445085e893f81100ffbfa3
MD5 e1c162cdeac5389c2b88059920958879
BLAKE2b-256 a8bb0780ca3df9eac6bb659d3445ce1c4ef6cf34024dec83ade11517dc97e48d

See more details on using hashes here.

File details

Details for the file atheon_codex-1.0.7-py3-none-any.whl.

File metadata

  • Download URL: atheon_codex-1.0.7-py3-none-any.whl
  • Upload date:
  • Size: 22.1 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 atheon_codex-1.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 3f40770ac8afbc256f8423332565a5efb8b62b43cf8b0a57c58dfa864492408f
MD5 5d9ef9a2516de1f6af07e128a375bc12
BLAKE2b-256 ec0c50514ec8e01cbab8ac4d0d6d6bf736681a885696e4ec53da57812e94180f

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