Pylogbeat

2.1.0 · active · verified Sun Apr 12

PyLogBeat is a simple, incomplete implementation of the Beats protocol used by Elastic Beats and Logstash. It enables reliable data transfer by having the server acknowledge received data, allowing the client to know whether and what to resend. The library is actively maintained, with a recent major release (2.1.0) in late 2025, and continues to support modern Python environments.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to send a single log message to a Logstash or Beats input plugin using `PyLogBeatClient`. It utilizes a context manager for automatic connection and disconnection, and shows a basic message structure. Remember to set `LOGSTASH_HOST` and `LOGSTASH_PORT` environment variables or update the default values.

import os
from datetime import datetime
from pylogbeat import PyLogBeatClient

# Configure connection details (replace with your Logstash/Beats input host and port)
HOST = os.environ.get('LOGSTASH_HOST', 'localhost')
PORT = int(os.environ.get('LOGSTASH_PORT', 5959))

# Example message in Logstash format
message = {
    '@timestamp': datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%S.%fZ'),
    '@version': '1',
    'message': 'hello world from pylogbeat',
    'level': 'INFO',
    'host': 'my-python-app'
}

try:
    with PyLogBeatClient(HOST, PORT, ssl_enable=False) as client:
        client.send([message])
        print(f"Sent message to {HOST}:{PORT}")
except Exception as e:
    print(f"Failed to send message: {e}")

view raw JSON →