Recount
Python

Getting started

Install the Recount Python SDK, add your API key and send your first decision trace in a few minutes.

1. Install

pip install recount-sdk

2. Get an API key

Sign in to the Recount dashboard and create an API key from Settings → API Keys.

3. Set your API key

Add RECOUNT_API_KEY to your environment. Recount reads it automatically on startup - no init() call needed.

# .env or shell export
RECOUNT_API_KEY=your_api_key_here

If no key is found, the SDK disables itself silently - no errors are thrown and no data is sent. This makes it safe to leave instrumentation in place across environments.

To override the ingest URL or enable debug logging, call recount.init() explicitly at startup - see Traces & spans.

4. Wrap your first trace

import asyncio
import recount


async def main():
    async def trace_fn():
        # your work here
        result = {"answer": 42}
        recount.add_span("json", "Result", {"output": result})

    await recount.start_trace("My first trace", trace_fn)


asyncio.run(main())

That's it. The trace appears in the dashboard with its name, duration, and spans.

5. Add spans

Spans record the individual steps your system takes. Add them anywhere inside a start_trace callback:

async def trace_fn():
    recount.add_span("db", "Policy lookup", {
        "metadata": {"table": "policies", "queryType": "sql"},
        "input": {
            "query": "SELECT * FROM policies WHERE number = $1",
            "params": ["POL-8821-AU"],
        },
        "output": {"rows": 1},
    })

    recount.add_span("table", "Policy validation", {
        "output": recount.table()
            .from_records([
                {"check": "Policy active", "result": "Pass"},
                {"check": "Cover active at incident", "result": "Pass"},
                {"check": "Comprehensive cover", "result": "Pass"},
            ])
            .highlight_rows(lambda row: "success" if row["result"] == "Pass" else "danger")
            .build(),
    })

    recount.add_span("json", "Decision", {
        "output": {"claimId": "CLM-2024-03941", "decision": "approved"},
    })


await recount.start_trace(
    "Insurance claim - CLM-2024-03941",
    {"metadata": {"claimId": "CLM-2024-03941"}},
    trace_fn,
)

Next steps

On this page