> starmerx.io
[github]
← cd ../open-source
[open-source] · · Python · MIT

django-scout

A lightweight Django ORM slow-query analyzer. We use it internally—now it's open-sourced.

The last line of defense for slow Django ORM queries.

What it is

A middleware + management command combo. It does three things:

  1. Records the timing of every SQL statement per request
  2. Alerts on queries exceeding a threshold (e.g. 200ms) — written to logs or a webhook
  3. Management command can replay a given endpoint’s query history

Why not Django Debug Toolbar

The Debug Toolbar is too heavy—fine in dev, totally unusable in production. Scout is designed to be safe to attach in production.

How to use

INSTALLED_APPS += ['scout']
MIDDLEWARE += ['scout.middleware.SlowQueryMiddleware']

SCOUT = {
    'slow_threshold_ms': 200,
    'webhook_url': 'https://hooks.example.com/scout',
    'sample_rate': 0.1,  # only sample 10% of requests
}

What we use it for

  • Hunting ORM N+1 issues before release
  • Watching for slow-query regressions
  • Grabbing live query snapshots for newcomers during debugging

What it doesn’t do

  • It doesn’t persist every query (only a sample)
  • It doesn’t replace an APM (just a lightweight supplement)
  • It doesn’t rewrite SQL for you