graphyte: Python 3 library to send data to a Graphite metrics server

graphyte is a small Python library that sends data to a Graphite metrics server. We wrote it because the existing graphitesend library didn’t support Python 3, and also required gevent for asyncronous use. graphyte is compatible with Python 3.4+ as well as Python 2.7, and uses the standard library’s threading module for asynchronous use.

We’ve recently started to use Python 3.5 in production at Jetsetter for various image processing tasks, so compatibility with Python 3.x is important to us. The library is small and stand-alone (pure Python, no external dependencies), so it wasn’t hard to release it as open source.

Jetsetter is using the official PyPI version in our own server and it’s working well so far! Here’s a Grafana screenshot showing one of the metrics we’re pushing through using graphyte:

Grafana screenshot

graphyte is on the Python Package Index (PyPI), so to install it, fire up a command prompt, activate your virtualenv if you’re using one, and type:

pip install graphyte

Using graphyte is simple – just call init() to initialize the default sender and then send() to send a message. For example, to send system.sync.foo.bar 42 {timestamp}\n to graphite.example.com:2003 synchronously:

import graphyte
graphyte.init('graphite.example.com', prefix='system.sync')
graphyte.send('foo.bar', 42)

If you want to send asynchronously on a background thread (for example, in a web server context), just specify a send interval. For example, this will setup a background thread to send every 10 seconds:

graphyte.init('graphite.example.com', prefix='async', interval=10)
graphyte.send('foo.bar', 42)

For (moderately) more advanced examples and other info, see the Jetsetter/graphyte repo on GitHub.

Enjoy! And let us know if you have any feedback.