Python Setup
Get started in under 3 minutes with our easy to install Python agent.
Installation
The latest scout-apm
package supports Django 3.2+.
scout-apm
package.
AInstall the scout-apm
package:
pip install scout-apm
BConfigure Scout in your settings.py
file:
# settings.py
INSTALLED_APPS = [
"scout_apm.django", # should be listed first
# ... other apps ...
]
# Scout settings
SCOUT_MONITOR = True
SCOUT_KEY = "[AVAILABLE IN THE SCOUT UI]"
SCOUT_NAME = "A FRIENDLY NAME FOR YOUR APP"
If you wish to configure Scout via environment variables, use SCOUT_MONITOR
, SCOUT_NAME
, and SCOUT_KEY
instead of providing these settings in settings.py
.
SCOUT_MONITOR
and SCOUT_KEY
via config vars. Only SCOUT_NAME
is additionally required.
CDeploy.
It takes approximately five minutes for your data to first appear within the Scout UI.
The latest scout-apm
package supports Flask 0.10+.
AInstall the scout-apm
package:
pip install scout-apm
BConfigure Scout inside your Flask app:
from scout_apm.flask import ScoutApm
# Setup a flask 'app' as normal
# Attach ScoutApm to the Flask App
ScoutApm(app)
# Scout settings
app.config["SCOUT_MONITOR"] = True
app.config["SCOUT_KEY"] = "[AVAILABLE IN THE SCOUT UI]"
app.config["SCOUT_NAME"] = "A FRIENDLY NAME FOR YOUR APP"
If you wish to configure Scout via environment variables, use SCOUT_MONITOR
, SCOUT_NAME
, and SCOUT_KEY
and remove the calls to app.config
.
SCOUT_MONITOR
and SCOUT_KEY
via config vars. Only SCOUT_NAME
is additionally required.
CDeploy.
It takes approximately five minutes for your data to first appear within the Scout UI.
Flask SQLAlchemy
Instrument flask-sqlalchemy queries by calling instrument_sqlalchemy()
on your SQLAlchemy
instance:
from flask_sqlalchemy import SQLAlchemy
from scout_apm.flask.sqlalchemy import instrument_sqlalchemy
app = ... # Your Flask app
db = SQLAlchemy(app)
instrument_sqlalchemy(db)
Scout supports FastAPI through the Starlette instrumentation. General instructions for a FastAPI app:
AInstall the scout-apm
package:
pip install scout-apm
BAttach the Scout middleware to your FastAPI app:
from fastapi import FastAPI
from scout_apm.api import Config
from scout_apm.async_.starlette import ScoutMiddleware
Config.set(
key="[AVAILABLE IN THE SCOUT UI]",
name="A FRIENDLY NAME FOR YOUR APP",
monitor=True,
)
app = FastAPI()
app.add_middleware(ScoutMiddleware)
If you wish to configure Scout via environment variables, use SCOUT_MONITOR
, SCOUT_NAME
, and SCOUT_KEY
and pass an empty dictionary to config
.
SCOUT_MONITOR
and SCOUT_KEY
via config vars. Only SCOUT_NAME
is additionally required.
CDeploy.
It takes approximately five minutes for your data to first appear within the Scout UI.
The latest scout-apm
package supports Celery 3.1+.
AInstall the scout-apm
package:
pip install scout-apm
BConfigure Scout in your Celery application file:
import scout_apm.celery
from scout_apm.api import Config
from celery import Celery
app = Celery('tasks', backend='redis://localhost', broker='redis://localhost')
# If you are using app.config_from_object() to point to your Django settings
# and have configured Scout there, configuring here is not necessary:
Config.set(
key="[AVAILABLE IN THE SCOUT UI]",
name="Same as Web App Name",
monitor=True,
)
scout_apm.celery.install(app)
The app
argument is optional and was added in version 2.12.0, but you should provide it for complete instrumentation.
If you wish to configure Scout via environment variables, use SCOUT_MONITOR
, SCOUT_NAME
, and SCOUT_KEY
instead of calling Config.set
.
SCOUT_MONITOR
and SCOUT_KEY
via config vars. Only SCOUT_NAME
is additionally required.
CDeploy.
It takes approximately five minutes for your data to first appear within the Scout UI.
Tasks will appear in the "Background Jobs" area of the Scout UI.
SQLAlchemy
To instrument SQLAlchemy queries:
from scout_apm.sqlalchemy import instrument_sqlalchemy
# Assuming something like engine = create_engine('sqlite:///:memory:', echo=True)
instrument_sqlalchemy(engine)
Flask SQLAlchemy
Instrument flask-sqlalchemy queries by calling instrument_sqlalchemy()
on your SQLAlchemy
instance:
from flask_sqlalchemy import SQLAlchemy
from scout_apm.flask.sqlalchemy import instrument_sqlalchemy
app = ... # Your Flask app
db = SQLAlchemy(app)
instrument_sqlalchemy(db)