This article explains how to set up an environment to make the most of the Datadog API. At the end, you will be able to pull or push events, metrics, and monitors from Datadog’s public API to a local file.
Prerequisite: Python and
pip installed on your localhost. If you are on Windows, see the Python documentation.
Open a terminal.
Verify the directory:
pwd on macOS,
dir on Windows.
Create a new folder:
Enter the folder:
Download the script api_query_data.py to the folder created in step 3 and edit it:
<YOUR_DD_APP_KEY> with your Datadog API and app keys.
system.cpu.idle with a metric you want to fetch. A list of your metrics is displayed in the Datadog Metric Summary page.
c. Optionally, replace
* with a host to filter the data. A list of your hosts is displayed in the Datadog Infrastructure List page.
d. Optionally, change the time period to collect the data. The current setting is 3600 seconds (one hour). Note: If you run this too aggressively, you may hit the Datadog API limits.
e. Save your file and confirm its location.
Once the above is complete:
source venv/bin/activate(Mac/Linux) or
pip install datadogto install the Datadog API package. This enables the Python file to interact with the Datadog API.
If successful, you will see data in the terminal and a file created in your folder named
To see additional examples, see our API documentation.