❮ Back to FAQ

Python Frameworks

How does Scout integrate with Django?

Scout automatically inserts middleware into your Django app on startup. It adds middleware at the start and end of your stack to profile middleware and views.

To customize middleware order, include Scout middleware manually:

MIDDLEWARE = [
    # any middleware to run first
    "scout_apm.django.middleware.MiddlewareTimingMiddleware",
    # your normal middleware
    "scout_apm.django.middleware.ViewTimingMiddleware",
    # any middleware to run last
]

Scout detects custom placement and won’t auto-insert.

How do I instrument Flask-SQLAlchemy?

Call instrument_sqlalchemy() on your SQLAlchemy instance:

from flask_sqlalchemy import SQLAlchemy
from scout_apm.flask.sqlalchemy import instrument_sqlalchemy

app = Flask(__name__)
db = SQLAlchemy(app)
instrument_sqlalchemy(db)

How do I instrument standalone SQLAlchemy?

from scout_apm.sqlalchemy import instrument_sqlalchemy

engine = create_engine('sqlite:///:memory:')
instrument_sqlalchemy(engine)

What other Python libraries are supported?

Scout instruments these additional libraries: - Bottle - Dash - Dramatiq - Falcon - Huey - Hug - RQ - Starlette

Contact support@scoutapm.com if you need a library that’s not listed.

How do I create a custom instrumented Cron job?

#!/usr/bin/env python
import requests
import scout_apm.api

config = {
    "name": "My App Name",
    "key": "YOUR_SCOUT_KEY",
    "monitor": True,
}

scout_apm.api.install(config=config)

with scout_apm.api.BackgroundTransaction("Daily Sync"):
    response = requests.get("https://api.example.com/sync")
    # process response

The job appears under “Background Jobs” in the Scout UI.

Ready to Optimize Your App?

Join engineering teams who trust Scout Monitoring for hassle-free performance monitoring. With our 3-step setup, powerful tooling, and responsive support, you can quickly identify and fix performance issues before they impact your users.