Install & Compatibility
Where this runs
tested against v0.1.4 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 1.116s · 28.4MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 3.9s · import 1.025s · 29MB
27MB installed
● package 27MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
API
✓ from flask_datadog import API
StatsD
✓ from flask_datadog import StatsD
✗ from flask.ext.datadog import StatsD
The 'flask.ext' import path was deprecated in Flask 0.11 and removed in Flask 1.0. Direct import from 'flask_datadog' is required for modern Flask versions.
This quickstart initializes Flask-Datadog for both StatsD metric submission and Datadog API interactions. It demonstrates incrementing a custom metric on a successful route and another on an error route. Ensure `DATADOG_STATSD_HOST`, `DATADOG_STATSD_PORT`, `DATADOG_API_KEY`, and `DATADOG_APP_KEY` environment variables are set for full functionality, though StatsD will default to localhost:8125.
from flask import Flask
from flask_datadog import API, StatsD
import os
app = Flask(__name__)
# Configure Datadog API and StatsD settings
app.config['STATSD_HOST'] = os.environ.get('DATADOG_STATSD_HOST', 'localhost')
app.config['STATSD_PORT'] = int(os.environ.get('DATADOG_STATSD_PORT', '8125'))
app.config['DATADOG_API_KEY'] = os.environ.get('DATADOG_API_KEY', '')
app.config['DATADOG_APP_KEY'] = os.environ.get('DATADOG_APP_KEY', '')
statsd = StatsD(app)
dogapi = API(app)
@app.route('/')
def hello():
statsd.increment('my_flask_app.requests')
return 'Hello, Datadog!'
@app.route('/error')
def error_route():
statsd.increment('my_flask_app.errors')
# Example of API usage (requires valid API/App keys)
# if dogapi.api_key and dogapi.app_key:
# dogapi.Event.create('An error occurred in Flask app',
# tags=['env:dev', 'service:my-app'])
raise Exception('This is a test error!')
if __name__ == '__main__':
# Ensure the Datadog Agent is running and accessible at STATSD_HOST:STATSD_PORT
# For API calls, ensure DATADOG_API_KEY and DATADOG_APP_KEY are set.
app.run(debug=True)
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'flask.ext.datadog'
You are attempting to import `flask_datadog` using the deprecated `flask.ext` namespace, which was removed in Flask 1.0.
fixChange your import statement from `from flask.ext.datadog import ...` to `from flask_datadog import ...`.
ConnectionRefusedError: [Errno 111] Connection refused
The Datadog Agent's DogStatsD server is not running or is not accessible at the configured `STATSD_HOST` and `STATSD_PORT`.
fixEnsure the Datadog Agent is installed and running, and that its DogStatsD port (default 8125) is open and reachable from your Flask application. Verify `app.config['STATSD_HOST']` and `app.config['STATSD_PORT']` are correctly set.
Upgrade
Version history
0.1.4latest on PyPI · released Jan 16, 2017
Audit
Dependencies
FlaskrequiredCore web framework integration.
datadogrequiredProvides the underlying DogStatsD and Datadog API client functionality.