Metadata-Version: 2.4
Name: keeto
Version: 0.2.1
Summary: Zero-config AI observability for Python — automatic tracing, cost tracking, and dashboards for LLM calls and custom pipelines
Project-URL: Homepage, https://github.com/bythebug/keeto
Project-URL: Repository, https://github.com/bythebug/keeto
Project-URL: Issues, https://github.com/bythebug/keeto/issues
Project-URL: Changelog, https://github.com/bythebug/keeto/blob/main/CHANGELOG.md
Author-email: Suraj Van Verma <surajvanv@gmail.com>
License: MIT License
        
        Copyright (c) 2026 Suraj Van Verma
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: ai,anthropic,debugging,llm,observability,openai,tracing
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Debuggers
Classifier: Topic :: System :: Monitoring
Classifier: Typing :: Typed
Requires-Python: >=3.11
Requires-Dist: anyio>=4.0
Requires-Dist: httpx>=0.25
Requires-Dist: pydantic>=2.0
Requires-Dist: rich>=13.0
Requires-Dist: typer>=0.12
Provides-Extra: all
Requires-Dist: aiosqlite>=0.19; extra == 'all'
Requires-Dist: asyncpg>=0.29; extra == 'all'
Requires-Dist: fastapi>=0.110; extra == 'all'
Requires-Dist: opentelemetry-exporter-otlp-proto-grpc>=1.24; extra == 'all'
Requires-Dist: opentelemetry-exporter-otlp-proto-http>=1.24; extra == 'all'
Requires-Dist: opentelemetry-sdk>=1.24; extra == 'all'
Requires-Dist: textual>=0.70; extra == 'all'
Requires-Dist: uvicorn[standard]>=0.29; extra == 'all'
Provides-Extra: dev
Requires-Dist: aiosqlite>=0.19; extra == 'dev'
Requires-Dist: fastapi>=0.110; extra == 'dev'
Requires-Dist: hypothesis>=6.100; extra == 'dev'
Requires-Dist: pyright>=1.1; extra == 'dev'
Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
Requires-Dist: pytest-benchmark>=4.0; extra == 'dev'
Requires-Dist: pytest-cov>=5.0; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Requires-Dist: respx>=0.21; extra == 'dev'
Requires-Dist: ruff>=0.4; extra == 'dev'
Requires-Dist: syrupy>=4.0; extra == 'dev'
Requires-Dist: textual>=0.70; extra == 'dev'
Requires-Dist: uvicorn[standard]>=0.29; extra == 'dev'
Provides-Extra: docs
Requires-Dist: mkdocs-material>=9.5; extra == 'docs'
Requires-Dist: mkdocstrings[python]>=0.25; extra == 'docs'
Provides-Extra: otel
Requires-Dist: opentelemetry-exporter-otlp-proto-grpc>=1.24; extra == 'otel'
Requires-Dist: opentelemetry-exporter-otlp-proto-http>=1.24; extra == 'otel'
Requires-Dist: opentelemetry-sdk>=1.24; extra == 'otel'
Provides-Extra: postgres
Requires-Dist: asyncpg>=0.29; extra == 'postgres'
Provides-Extra: sqlite
Requires-Dist: aiosqlite>=0.19; extra == 'sqlite'
Provides-Extra: tui
Requires-Dist: textual>=0.70; extra == 'tui'
Provides-Extra: web
Requires-Dist: fastapi>=0.110; extra == 'web'
Requires-Dist: uvicorn[standard]>=0.29; extra == 'web'
Description-Content-Type: text/markdown

# Keeto

**Zero-config AI observability for Python.** Automatic tracing, cost tracking, and dashboards for every LLM call — plus a `@trace` decorator to instrument your own pipelines.

```python
from keeto import monitor
monitor.start()

# Your existing code — completely unchanged
response = client.chat.completions.create(model="gpt-4o", messages=[...])

monitor.dashboard()
```

```
┌─────────────────────────────────────────────────────────────┐
│  Traces: 42   Cost: $0.0312   Tokens: 18,400   Errors: 0   │
├───────────────┬──────────┬────────┬─────────┬──────────────┤
│ Model         │ Calls    │ P50    │ P95     │ Cost         │
├───────────────┼──────────┼────────┼─────────┼──────────────┤
│ gpt-4o        │ 28       │ 843ms  │ 2.1s    │ $0.0289      │
│ gpt-4o-mini   │ 14       │ 312ms  │ 680ms   │ $0.0023      │
└───────────────┴──────────┴────────┴─────────┴──────────────┘
```

---

## Install

```bash
pip install keeto
```

```bash
# SQLite persistence + interactive TUI
pip install "keeto[sqlite,tui]"

# Browser dashboard
pip install "keeto[sqlite,web]"
```

---

## Two ways to use Keeto

### 1. Auto-detect AI SDK calls

Drop two lines into your app. Keeto scans installed packages and patches their HTTP transport — no wrappers, no code changes.

```python
from keeto import monitor
monitor.start()

# OpenAI, Anthropic, LangChain, Gemini … all captured automatically
```

```
keeto: loaded plugins → openai, anthropic
```

### 2. Instrument your own pipeline

Use `@trace` to add stage-by-stage timing to RAG pipelines, multi-step workflows, or any custom framework:

```python
from keeto import monitor, trace

monitor.start()

@trace("embedding")
def embed(text: str) -> list[float]: ...

@trace("retrieval")
def search(vec: list[float]) -> list[str]: ...

@trace("rerank")
def rerank(docs: list[str], query: str) -> list[str]: ...

@trace("llm")
def generate(docs: list[str]) -> str: ...

# Run your pipeline
answer = generate(rerank(search(embed("What is the capital of France?")), "..."))

monitor.pipeline_breakdown()
```

```
Trace a3f8bc12

embedding        18 ms
retrieval        12 ms
rerank           65 ms
llm            1100 ms
──────────────────────
Total          1195 ms

Slowest stage: llm (92.1%)
```

`@trace` works on sync and async functions. Common stage names (`embedding`, `retrieval`, `llm`, `rerank`, `search`) are mapped to the correct span kind automatically.

---

## Features

| Feature | Details |
|---|---|
| **Auto-detection** | Patches OpenAI, Anthropic, LangChain, LlamaIndex, LiteLLM, Gemini, Ollama, and more at `monitor.start()` |
| **`@trace` decorator** | Instrument any sync or async function as a named, timed span |
| **Cost tracking** | Input tokens, output tokens, cached tokens, and USD cost on every span |
| **Budget alerts** | `monitor.set_budget(daily_usd=10.0)` — fires a warning before surprise bills |
| **Token budgets** | `monitor.set_token_budget(monthly=1_000_000)` |
| **PII scrubbing** | `scrub_pii=True` redacts emails, SSNs, phone numbers from stored spans |
| **Dashboards** | Rich table, interactive TUI (`keeto[tui]`), or browser dashboard (`keeto[web]`) |
| **Pipeline breakdown** | `monitor.pipeline_breakdown()` — stage-by-stage latency table |
| **Recommendations** | `monitor.recommendations()` — flags oversized prompts, repeated calls, cache candidates |
| **Export** | JSON, CSV, OpenTelemetry (OTLP), LangSmith, MLflow |
| **Replay** | `trace.replay()` — re-sends the exact original request |
| **Storage** | In-memory (default), SQLite (`keeto[sqlite]`), PostgreSQL (`keeto[postgres]`) |
| **<1ms overhead** | Non-blocking queue — interceptor enqueues and returns immediately |

---

## Integrations

Keeto auto-detects whichever SDKs you have installed:

- **OpenAI** — chat, embeddings, tools, streaming
- **Anthropic** — messages, tools, streaming
- **LangChain** — chains, agents, retrievers
- **LlamaIndex** — query engines, agents
- **LiteLLM** — all providers via callback
- **Google Gemini** — generate_content, streaming
- **Ollama** — local models
- **OpenAI Agents SDK** — traces, tool calls
- **PydanticAI** — agents, tools
- **FastAPI** — per-request trace context middleware
- **vLLM** — local inference server
- **Custom / own framework** — `@trace` decorator

---

## Configuration

```python
from keeto import Monitor
from keeto.storage.sqlite import SQLiteStorage

monitor = Monitor(
    storage=SQLiteStorage("./keeto.db"),   # persist across restarts
    sample_rate=0.1,                        # capture 10% in production
    scrub_pii=True,                         # redact PII before storage
    store_prompts=True,                     # set False for metadata-only
)
monitor.start()

monitor.set_budget(daily_usd=10.0, session_usd=2.0)
monitor.set_token_budget(monthly=1_000_000)
```

## Manual span context

For fine-grained control, use `monitor.span()` directly to group stages under a named root:

```python
with monitor.span("rag-pipeline") as ctx:
    ctx.set_attribute("query", query)
    vec   = embed(query)
    docs  = search(vec)
    answer = generate(docs, query)
```

---

## Dashboard modes

```python
monitor.dashboard()           # Rich table in terminal (no extra deps)
monitor.dashboard("tui")      # Interactive TUI — requires keeto[tui]
monitor.dashboard("web")      # Browser dashboard — requires keeto[web]
```

---

## CLI

```bash
keeto traces                  # list recent traces
keeto dashboard               # launch TUI
keeto analyze                 # print recommendations
keeto export --format json    # export to file
keeto replay <trace-id>       # re-send a captured request
keeto doctor                  # diagnose setup issues
```

---

## Links

- [Documentation](https://bythebug.github.io/keeto)
- [Quickstart](https://bythebug.github.io/keeto/quickstart/)
- [Custom Instrumentation (@trace)](https://bythebug.github.io/keeto/integrations/custom/)
- [PyPI](https://pypi.org/project/keeto)
- [Changelog](CHANGELOG.md)

---

## License

MIT
