Registry / devops / sdnotify

sdnotify

JSON →
library0.3.2pypypi✓ verified 35d ago

sdnotify provides a pure Python implementation of systemd's service notification protocol (sd_notify). It allows Python services to communicate their status, readiness, and other information back to systemd, enabling robust service management. The current version is 0.3.2, with releases being infrequent, primarily for packaging or minor internal improvements.

devops
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

from sdnotify import SystemdNotifier

This quickstart demonstrates how to initialize `SystemdNotifier` and send status messages, including `READY=1` and `STATUS` updates, to systemd. This script should be run as a `Type=notify` service under systemd to observe the notifications.

import time from sdnotify import SystemdNotifier def main(): notifier = SystemdNotifier() print("Sending NOTIFY_SOCKET check (silently fails if not running under systemd)") # Send 'READY=1' to signal that the service is initialized notifier.notify("READY=1") print("Service ready. Working...") for i in range(1, 4): status_message = f"STATUS=Working on task {i} of 3..." print(status_message) notifier.notify(status_message) time.sleep(2) # Simulate work # Send 'STOPPING=1' or just exit (systemd can infer STOPPING upon exit) print("Service finished work. Sending STOPPING=1.") notifier.notify("STOPPING=1") if __name__ == "__main__": main()
Debug
Known footguns
gotchaNotifications are silently ignored if the `NOTIFY_SOCKET` environment variable is not set. This means your Python service is likely not running under systemd, or systemd is not configured to listen for notifications (e.g., `Type=notify` is missing in the unit file).
gotchaSystemd expects a `READY=1` notification to mark the service as successfully started. Forgetting to send this can cause systemd to prematurely consider the service failed or stalled, leading to restarts or timeouts.
breakingVersions prior to `0.3.0` were considered experimental and may have been non-functional or had an unstable API. The `sdnotify` functionality became reliably available starting with `0.3.0`.
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
0 hits · last 30 days

No traffic data recorded yet.

Resources