Pylogbeat
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
- breaking Version 2.1.0 dropped support for Python versions older than 3.11. If you are on an older Python version, you must upgrade Python or stick to `pylogbeat < 2.1.0`.
- breaking The `six` compatibility library dependency was removed in version 2.0.0. This makes `pylogbeat` a Python 3-only library from this version onwards.
- gotcha Due to a known bug (logstash-plugins/logstash-input-beats#342), Logstash requires specific versions to correctly receive data from `pylogbeat`.
- gotcha The `PyLogBeatClient` constructor's `use_logging` argument defaults to `False`. If `pylogbeat` is used as part of your logging system, setting `use_logging=True` might lead to recursive logging issues during shutdown.
- gotcha The implemented Beats protocol in `pylogbeat` is described as 'incomplete' as the protocol itself is not yet officially specified. While core functionality like sending data and awaiting ACK is present, some details might be missing.
Install
-
pip install pylogbeat
Imports
- PyLogBeatClient
from pylogbeat import PyLogBeatClient
Quickstart
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}")