The Datadog Python library
Project description
The Datadog Python library
The Datadog Python Library is a collection of tools suitable for inclusion in existing Python projects or for the development of standalone scripts. It provides an abstraction on top of Datadog's raw HTTP interface and the Agent's DogStatsD metrics aggregation server, to interact with Datadog and efficiently report events and metrics.
- Library Documentation: https://datadogpy.readthedocs.io/en/latest/
- HTTP API Documentation: https://docs.datadoghq.com/api/
- DatadogHQ: https://datadoghq.com
See CHANGELOG.md for changes.
Installation
To install from pip:
pip install datadog
To install from source:
python setup.py install
Datadog API
Find below a working example for submitting an event to your Event Stream:
from datadog import initialize, api
options = {
'api_key': '<YOUR_API_KEY>',
'app_key': '<YOUR_APP_KEY>'
}
initialize(**options)
title = "Something big happened!"
text = 'And let me tell you all about it here!'
tags = ['version:1', 'application:web']
api.Event.create(title=title, text=text, tags=tags)
Consult the full list of supported Datadog API endpoints with working code examples in the Datadog API documentation.
Note: The full list of available Datadog API endpoints is also available in the Datadog Python Library documentation
Environment Variables
As an alternate method to using the initialize function with the options parameters, set the environment variables DATADOG_API_KEY and DATADOG_APP_KEY within the context of your application.
If DATADOG_API_KEY or DATADOG_APP_KEY are not set, the library attempts to fall back to Datadog's APM environmnent variable prefixes: DD_API_KEY and DD_APP_KEY.
from datadog import initialize, api
# Assuming you've set `DD_API_KEY` and `DD_APP_KEY` in your env,
# initialize() will pick it up automatically
initialize()
title = "Something big happened!"
text = 'And let me tell you all about it here!'
tags = ['version:1', 'application:web']
api.Event.create(title=title, text=text, tags=tags)
DogStatsD
In order to use DogStatsD metrics, the Agent must be running and available.
Instantiate the DogStatsD client
Once the Datadog Python Library is installed, instantiate the StatsD client in your code:
from datadog import statsd
options = {
'statsd_host':'127.0.0.1',
'statsd_port':8125
}
initialize(**options)
See the full list of available DogStatsD client instantiation parameters.
Origin detection over UDP
Origin detection is a method to detect which pod DogStatsD packets are coming from in order to add the pod's tags to the tag list.
The DogStatsD client attaches an internal tag, entity_id. The value of this tag is the content of the DD_ENTITY_ID environment variable if found, which is the pod's UID. The Datadog Agent uses this tag to add container tags to the metrics. To avoid overwriting this global tag, make sure to only append to the constant_tags list.
To enable origin detection over UDP, add the following lines to your application manifest
env:
- name: DD_ENTITY_ID
valueFrom:
fieldRef:
fieldPath: metadata.uid
Usage
Metrics
After the client is created, you can start sending custom metrics to Datadog. See the dedicated Metric Submission: DogStatsD documentation to see how to submit all supported metric types to Datadog with working code examples:
- Submit a COUNT metric.
- Submit a GAUGE metric.
- Submit a SET metric
- Submit a HISTOGRAM metric
- Submit a TIMER metric
- Submit a DISTRIBUTION metric
Some options are suppported when submitting metrics, like applying a Sample Rate to your metrics or tagging your metrics with your custom tags.
Events
After the client is created, you can start sending events to your Datadog Event Stream. See the dedicated Event Submission: DogStatsD documentation to see how to submit an event to your Datadog Event Stream.
Service Checks
After the client is created, you can start sending Service Checks to Datadog. See the dedicated Service Check Submission: DogStatsD documentation to see how to submit a Service Check to Datadog.
Thread Safety
DogStatsD and ThreadStats are thread-safe.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file datadog-0.33.0.tar.gz.
File metadata
- Download URL: datadog-0.33.0.tar.gz
- Upload date:
- Size: 101.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.2.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/2.7.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bce73f33a4496b004402baa502251150e3b48a48f610ff89d4cd110b366ee0ab
|
|
| MD5 |
5dbf2ee30c474e27e0eb2b5c38229296
|
|
| BLAKE2b-256 |
0d2eb791fe45e7536616d4db09feba8616003620619f3c486cd9e8bd42ad741f
|
File details
Details for the file datadog-0.33.0-py2.py3-none-any.whl.
File metadata
- Download URL: datadog-0.33.0-py2.py3-none-any.whl
- Upload date:
- Size: 90.1 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.2.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/2.7.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
22d3c935e83de02b64efed635ac5fb45db26e152ac759105ec6d5a7ed8b9f6a9
|
|
| MD5 |
07fa44d260d228b917694c72048e23a5
|
|
| BLAKE2b-256 |
49505f11ce29a5fc1c5b759220c49b66d8a693603b58b113dd35659ec156f7c7
|