graypy is a Python library that provides logging handlers for sending messages in the Graylog Extended Log Format (GELF). It integrates with Python's standard `logging` module and supports various transport protocols including UDP, TCP, TLS, HTTP, and RabbitMQ. The current version is 2.1.0, and while there isn't a strict release cadence, major versions have introduced breaking changes.
Install & Compatibility
Where this runs
tested against v2.1.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.095s · 18MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 1.5s · import 0.084s · 19MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
from graypy import GELFUDPHandler
from graypy import GELFTCPHandler
from graypy import GELFTLSHandler
from graypy import GELFHTTPHandler
from graypy import GELFRabbitHandler
`GELFHandler` was deprecated and removed in graypy 1.x.x; use `GELFUDPHandler` instead.
from graypy import GELFUDPHandler
`GELFTcpHandler` was deprecated and restructured into `GELFTCPHandler` and `GELFTLSHandler` in graypy 1.x.x.
from graypy import GELFTCPHandler
This quickstart demonstrates how to configure a basic UDP logging handler (`GELFUDPHandler`) to send messages to a Graylog server. It uses environment variables for the Graylog host and port, which is a common practice for configuration management. Ensure your Graylog server has a GELF UDP input configured on the specified port.
import logging
import graypy
import os
# Configure Graylog host and port, using environment variables for security
GRAYLOG_HOST = os.environ.get('GRAYLOG_HOST', 'localhost')
GRAYLOG_PORT = int(os.environ.get('GRAYLOG_PORT', 12201))
# Get a logger instance
my_logger = logging.getLogger('my_app_logger')
my_logger.setLevel(logging.DEBUG)
# Create a GELF UDP handler
handler = graypy.GELFUDPHandler(GRAYLOG_HOST, GRAYLOG_PORT)
my_logger.addHandler(handler)
# Send a log message
my_logger.debug('Hello Graylog from graypy!')
my_logger.info('This is an informational message.')
my_logger.warning('Something might be wrong here.')
try:
1 / 0
except ZeroDivisionError:
my_logger.exception('An error occurred!')
print(f"Log messages sent to Graylog at {GRAYLOG_HOST}:{GRAYLOG_PORT} (UDP).")
Upgrade
Version history
Breaking-change detection hasn't run for this library yet.
Audit
Security & dependencies
CVE tracking and dependency tree are planned for a later release.