▶ runtime-narrative
✦ v1.5.4 — Python 3.9+

Turn any Python execution into a
traceable story

Minimal logs when everything works. Surgical, LLM-powered diagnostics the moment something breaks. No restructuring of existing code required.

examples/basic.py
▶ Story started: Import Customers
✔ Load CSV 0.012s
✔ Validate Data 0.004s
❌ Failure at: Insert Records
ValueError: duplicate customer id
Location: app/db.py:47 insert_row
Code: raise ValueError("duplicate customer id")
Chain: ValueError ← sqlite3.IntegrityError
## Exact Why
A record with the same customer_id already exists (UNIQUE constraint).
## Targeted Fix
Use INSERT OR IGNORE, or check for an existing row before inserting.
Why runtime-narrative

Built for how engineers already talk about failures

"We ran Import Customers, it loaded the CSV, validated the rows, then failed during Insert Records." That's exactly what the library captures — automatically.

▶
Stories and stages

story() / stage() are dual sync/async context managers — or decorators, or auto-instrumentation. No restructuring needed.

↳
Sub-story tracing

Nest a story() inside an active one and it auto-links as a traceable child with its own success/failure and duration — no new API.

≡
Lean by default, rich on demand

A compressed stack summary and exact failure frame always; local-variable capture with automatic secret redaction only when you ask.

✦
Optional LLM diagnosis

Ollama, any OpenAI-compatible endpoint, or Anthropic Claude turns a traceback into an exact-cause explanation and a targeted fix.

⇄
Bring your own everything

Any object with handle(event) is a renderer; any object with analyze_failure(...) is an analyzer.

▣
Ships with real integrations

Console, JSON, SQLite, OpenTelemetry, Prometheus, HTML, webhooks, FastAPI, Django, Celery, gRPC — all built in.

Get started in a minute

Install, then wrap your code

The core package has no required dependencies beyond the standard library and python-dotenv.

bash
pip install runtime-narrative
bash
pip install "runtime-narrative[console,fastapi,anthropic]"
python
from runtime_narrative import story, stage

with story("Import Customers"):
    with stage("Load CSV"):
        rows = load_csv("customers.csv")
    with stage("Validate Data"):
        validate(rows)
    with stage("Insert Records"):
        db.insert(rows)

Read the full Quick Start →

Ready to see it fail on purpose?

Every example in the docs is a runnable script. Start with the Quick Start, or jump straight to the full API reference.