Skip to main content

RELP server/client for python

main

install

  • pip install relppy

example

server

import socketserver
from relppy.server import RelpStreamHandler
from relppy.protocol import Message


class MyHandler(RelpStreamHandler):
    def do_syslog(self, msg: Message):
        print(msg.data.decode("ascii"))


if __name__ == "__main__":
    srv = socketserver.TCPServer(("localhost", 10514), MyHandler)
    srv.serve_forever()

client

from relppy.client import RelpTCPClient

with RelpTCPClient(("localhost", 10514)) as cl:
    for m in ["hello", "world"]:
        fut= cl.send_command(b"syslog", m.encode())
        res = fut.result()
        print(f"sent: {m} -> {res}")

log handler

relppy comes with a logging handler that can be used with python logging. The handler has four special arguments.

spool_method=<function>

You can specify a spool method. This method is called with the log record instance as argument if the record could not be sent (e.g. relp log server down) to spool it for later resend. Writing the spool/resend methods is up to the developer.

exception_on_emit=<bool>

If exception_on_emit is True, the emit() method of the log handler raises an exception if the log message could not be sent. This results in an exception (e.g. Connection refused) when calling the logger (e.g. logger.info). This behavior is intended to be used in the resend method (see spool_method above) to ensure all spooled messages are delivered to the relp log server.

logger=<logging.Logger>

The logger instance that is used to log connection failures.

active_log_handlers=<List>

A list that the log handler is added to on init and removed from on close(). This is useful in multiprocessing programs/daemons to close all open loggers on exit.

Examples

import logging
from relppy.log_handler import RelpHandler

log_handler = RelpHandler(address=(server, port), facility="LOCAL7")

formatter = logging.Formatter('%(name)s: [%(levelname)s] %(message)s')
log_handler.setFormatter(formatter)
logger = logging.getLogger("my_logger")
logger.addHandler(log_handler)

Passing a SSL context enables TLS.

import ssl
import logging
from relppy.log_handler import RelpHandler

context = ssl.create_default_context(
    purpose=ssl.Purpose.SERVER_AUTH,
    cafile="/path/to/ca.cert",
)
context.load_cert_chain(certfile="/path/to/client-cert.pem",
                        keyfile="/path/to/client-key.pem")

log_handler = RelpHandler(address=(server, port),
                        facility="LOCAL7",
                        context=context)

formatter = logging.Formatter('%(name)s: [%(levelname)s] %(message)s')
log_handler.setFormatter(formatter)

logger = logging.getLogger("my_logger")
logger.addHandler(log_handler)

CLI command

relppy comes with a CLI command to send messages to a relp server rsyslog example.

relppy logger --logger-name audit-log --host servername --port port --log-level INFO --priority info --facility LOCAL7 "Test message"
relppy logger-tls --logger-name audit-log --host servername --port port --cafile /path/to/syslog-ca.pem --certfile /path/to/syslog-cert.pem --keyfile /path/to/syslog-key.pem --log-level INFO --priority info --facility LOCAL7 "Test message via TLS"

Metadata

Release files for relppy 0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for relppy 0.4
File Interpreter ABI Platform Actions
relppy-0.4-py3-none-any.whl Python 3 none any Details for relppy-0.4-py3-none-any.whl

Release files / relppy-0.4-py3-none-any.whl

Download URL relppy-0.4-py3-none-any.whl
Size 13.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b71900bf37d1b4076145353d6bd3595cca73e1053088d64fb6787afa1e759b09
BLAKE2b-256 checksum
How to use checksums
414fd3e246c7e8f1bd7909cc20acf988091765f3cf35de9a57b83b17a75acabc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Security for relppy 0.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page