The `datadog` Python library (`datadogpy`) provides convenient interfaces for interacting with Datadog's HTTP API and sending metrics, events, and service checks via DogStatsD. It supports both UDP and Unix Domain Socket (UDS) transports for DogStatsD and includes a CLI tool ('dog') for API operations. As of version 0.52.1, it continues to be actively maintained, focusing on core API interactions and DogStatsD client functionality.
pip install datadogVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize the Datadog client using environment variables for API and Application keys and then send both an event via the HTTP API and custom metrics via DogStatsD. Remember to have the Datadog Agent running for DogStatsD metrics.
Always check which library you need. If you need v2 API access, async support, or access to all new endpoints, `datadog-api-client` is generally preferred. For simpler v1 API interactions or DogStatsD, `datadog` is sufficient.
Initialize the client using `datadog.initialize(api_key="YOUR_API_KEY", app_key="YOUR_APP_KEY")` or, preferably, set environment variables `DATADOG_API_KEY` and `DATADOG_APP_KEY`. Never hardcode keys directly in production code.
Pass `api_host='https://api.datadoghq.eu'` (or your specific region's host) to `datadog.initialize()` or set the `DATADOG_HOST` environment variable.
Ensure the Datadog Agent is installed, running, and configured to receive DogStatsD metrics (default port 8125). Verify network reachability from your application to the Agent.
For distributed tracing, continuous profiling, and auto-instrumentation of frameworks (e.g., Flask, Django), install and use the `ddtrace` library (`pip install ddtrace`).
Run `pip install datadog` to install the library.
Rename your local Python file (e.g., from `datadog.py` to `my_datadog_script.py`) to avoid the naming conflict.
Initialize the library by calling `datadog.initialize(api_key='YOUR_API_KEY', app_key='YOUR_APP_KEY')` with valid keys, or set the `DATADOG_API_KEY` and `DATADOG_APP_KEY` environment variables.
Ensure the Datadog Agent is running and its DogStatsD server is active (default UDP port 8125). Verify the `statsd_host` and `statsd_port` parameters in your `datadog.initialize()` call. If running your application on a different host than the Agent, ensure `dogstatsd_non_local_traffic: true` is set in your Datadog Agent configuration.
datadog.initialize(api_key='YOUR_API_KEY', app_key='YOUR_APP_KEY') or set DATADOG_API_KEY and DATADOG_APP_KEY environment variables.