Registry / observability / graypy

graypy

JSON →
library2.1.0pypypi✓ verified 35d ago

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.

observabilityhttp-networking
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
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.095s · 18MB
glibc
py 3.103.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).")
Debug
Known footguns
breakingThe `GELFHandler` and `GELFTcpHandler` classes were removed in `graypy` version 1.x.x. Users migrating from 0.x.x to 1.x.x or newer must update their code to use `GELFUDPHandler`, `GELFTCPHandler`, or `GELFTLSHandler` respectively.
gotcha`GELFUDPHandler` sends logs via UDP, which is a connectionless protocol and does not guarantee message delivery. Critical logs that must not be lost should be sent via `GELFTCPHandler`, `GELFTLSHandler`, `GELFHTTPHandler`, or `GELFRabbitHandler` for more reliable transport.
gotchaWhen using `GELFRabbitHandler`, you must manually configure RabbitMQ with a GELF-compatible queue and bind it to a logging exchange. Graylog then consumes messages from this AMQP queue.
gotchaThere is no formal changelog maintained for `graypy` on GitHub, which can make it challenging to track specific changes, new features, or breaking alterations between versions.
gotchaWhen deploying `graypy` in containerized environments (e.g., with Docker or Kubernetes, especially with Django applications), ensure that the application container and the Graylog container are on the same network and configured with correct hostnames or IP addresses for communication.
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.

Agent activity
16 hits · last 30 days
gptbot
4
ahrefsbot
4
script
1
bytedance
1
Resources