Registry / devops / systemd-python

systemd-python

JSON →
library235pypypiunverified

systemd-python provides a Python interface for libsystemd, allowing Python applications to interact with systemd components like the journal, daemon management, and unit control. The current version is 235. Releases are infrequent and typically tied to major systemd project releases.

pip install systemd-python
INSTALL
IMPORT
SIG · SYSTEMD-PYTHON
S
systemd-python
devopspythonv235
Install
Import
Disk
Pass rate
0/ 10
Env Coverage0 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v? · pip install
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
build_error
glibc
py 3.103.920 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Journal
from systemd.journal import Journal
from systemd import Journal
Journal class is within the 'journal' submodule.
daemon.notify
from systemd import daemon
Daemon readiness and notification functions are directly under the 'systemd.daemon' module.

This quickstart demonstrates how to send a log message to the systemd journal using the `Journal` class. It includes custom fields for better discoverability and provides an error message if systemd-journald is not available, which is common when running on non-systemd systems or without proper access.

import os from systemd.journal import Journal # Get an environment variable, useful for identifying the service in the journal service_identifier = os.environ.get('SYSTEMD_UNIT', 'my_python_script.service') try: # Initialize the Journal object j = Journal() # Send a message to the systemd journal j.send( f'Hello from systemd-python! Test message from {service_identifier}.', PRIORITY='INFO', PYTHON_PROCESS=os.getpid(), # Example custom field SERVICE_NAME=service_identifier # Another custom field ) print(f"Message successfully sent to systemd journal from {service_identifier}.") except Exception as e: print(f"Failed to send message to systemd journal: {e}") print("Note: This script must be run on a Linux system with systemd-journald active and accessible.") print("You can view journal entries using: journalctl -f -t python-script")
Debug
Known issues
gotchaDirect `pip install systemd-python` is often discouraged on systemd-based Linux distributions. It's generally safer and recommended to use the distribution's provided package (e.g., `apt install python3-systemd` on Debian/Ubuntu, `dnf install python3-systemd` on Fedora/RHEL) to ensure compatibility with the system's `libsystemd`.
fix
Prefer using your distribution's package manager to install `python3-systemd`.
affects: All
breaking`systemd-python` is specifically designed for Linux systems utilizing systemd. It will not work on other operating systems (like macOS, Windows) or Linux distributions that do not use systemd (like Alpine Linux with OpenRC). Attempting to use it elsewhere will result in various errors, including `ModuleNotFoundError` or errors when trying to connect to systemd services.
fix
Ensure your environment is a systemd-based Linux distribution. For cross-platform applications, consider abstracting systemd-specific functionality.
affects: All
gotchaThe API is a low-level binding to `libsystemd`. Error handling often involves checking return codes, handling `JournaldError` or `SystemdError` exceptions, and understanding systemd-specific error messages, which can be less 'Pythonic' than other libraries. Some operations may require elevated privileges (e.g., interacting with D-Bus for unit control).
fix
Consult systemd documentation for specific error codes and expected behavior. Implement robust `try-except` blocks for `systemd.journal.JournaldError` or `systemd.SystemdError`. Be mindful of process privileges.
affects: All
Upgrade
Version history
235latest on PyPI · released Feb 11, 2023
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
Resources
systemd-python — pip install systemd-python · libregistry