Skip to main content

The Datadog Python library

Project description

The Datadog Python library

Build Status Documentation Status PyPI - Version PyPI - Downloads

Datadogpy is a collection of tools suitable for inclusion in existing Python projects or for development of standalone scripts. It provides an abstraction on top of Datadog's raw HTTP interface and the Agent's StatsD metrics aggregation server, to interact with Datadog and efficiently report events and metrics.

For usage of StatsD metrics, the Agent must be running and available.

See CHANGELOG.md for changes.

Installation

To install from pip:

pip install datadog

To install from source:

python setup.py install

Quick Start Guide

# Configure the module according to your needs
from datadog import initialize

options = {
    'api_key':'api_key',
    'app_key':'app_key'
}

initialize(**options)

# Use Datadog REST API client
from datadog import api

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)


# Use Statsd, a Python client for DogStatsd
from datadog import statsd

# Uncomment to set namespace or add tags to everything
# statsd.namespace = 'localdev'
# statsd.constant_tags = ['testing', 'dogstats']

statsd.increment('whatever')
statsd.gauge('foo', 42)

# Or ThreadStats, an alternative tool to collect and flush metrics, using Datadog REST API
from datadog import ThreadStats
stats = ThreadStats()
stats.start()
stats.increment('home.page.hits')

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 will attempt 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)

Thread Safety

DogStatsD and ThreadStats are thread-safe.

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. This tag will be used by the Datadog Agent to insert container tags to the metrics. You should only append to the constant_tags list to avoid overwriting this global tag.

To enable origin detection over UDP, add the following lines to your application manifest

env:
  - name: DD_ENTITY_ID
    valueFrom:
      fieldRef:
        fieldPath: metadata.uid

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

datadog-0.29.3.tar.gz (146.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

datadog-0.29.3-py2.py3-none-any.whl (72.9 kB view details)

Uploaded Python 2Python 3

File details

Details for the file datadog-0.29.3.tar.gz.

File metadata

  • Download URL: datadog-0.29.3.tar.gz
  • Upload date:
  • Size: 146.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/2.7.10

File hashes

Hashes for datadog-0.29.3.tar.gz
Algorithm Hash digest
SHA256 995e51d142ae3624c86c78369b268f23386bb207df5345d718c241718387875c
MD5 c445aa4585272722d262af1fd9b9218d
BLAKE2b-256 fac1034dde319c97dc90c23a9448e7b0834a74285a9c7112a8fe33361d32d861

See more details on using hashes here.

File details

Details for the file datadog-0.29.3-py2.py3-none-any.whl.

File metadata

  • Download URL: datadog-0.29.3-py2.py3-none-any.whl
  • Upload date:
  • Size: 72.9 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/2.7.10

File hashes

Hashes for datadog-0.29.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 0e33727bd9ef0b8201359accdf12f61fb58ab541bf4062693aca16653f8e7a0a
MD5 5b98c101e93a2892e4c07f10750b0da3
BLAKE2b-256 7382110a3978f07cfc58a4b4c1edac934d493ec2f174e0d18d23afed9c0829c9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page