Docs · SDK · Python

Python SDK.

Pure Python, no C extensions. Tested on 3.10, 3.11, 3.12, 3.13. FastAPI, Flask, Django middlewares included. structlog and stdlib-logging transports.

Install

pip install coderadar
# or: poetry add coderadar
# or: uv add coderadar

Init

import os
import coderadar

coderadar.init(
    dsn         = os.environ["CODERADAR_DSN"],
    project     = "veritize",
    environment = os.environ.get("ENV", "dev"),
    release     = os.environ.get("RELEASE_SHA"),
    sample_rate         = 1.0,
    traces_sample_rate  = 0.2,
    debug       = False,
    before_send = lambda ev: ev,
)

FastAPI

from fastapi import FastAPI
from coderadar.fastapi import CodeRadarMiddleware

app = FastAPI()
app.add_middleware(CodeRadarMiddleware)

# captures unhandled exceptions, attaches request context,
# propagates W3C tracecontext on outbound httpx calls.

Flask

from flask import Flask
from coderadar.flask import init_app

app = Flask(__name__)
init_app(app)

Django

# settings.py
MIDDLEWARE = [
    "coderadar.django.CodeRadarMiddleware",
    # ...rest of your middleware
]

Async / sync background jobs

from coderadar import capture_exception, set_user, set_tag, push_scope

set_tag("job", "drift_scan")

try:
    run_drift_scan()
except Exception as e:
    capture_exception(e)
    raise

# Scoped context (thread / task local)
with push_scope() as scope:
    scope.set_tag("step", "embed")
    do_embedding()

structlog transport

import structlog
from coderadar.structlog import processor

structlog.configure(processors=[
    processor(min_level="error"),
    structlog.processors.JSONRenderer(),
])

Celery

from coderadar.celery import celery_init

celery_init(app)  # captures task failures with task_id + args context

Notes

  • Default before_send strips fields named authorization, cookie, password, token, api_key, secret.
  • The SDK uses httpx internally for outbound shipping; install separately if not present.
  • On exit, coderadar.flush(timeout=2.0) blocks for up to 2s while the buffer drains.