{"library":"sdnotify","title":"sdnotify: Systemd Service Notification","description":"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.","language":"python","status":"active","last_verified":"Fri Apr 17","install":{"commands":["pip install sdnotify"],"cli":null},"imports":["from sdnotify import SystemdNotifier"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import time\nfrom sdnotify import SystemdNotifier\n\ndef main():\n    notifier = SystemdNotifier()\n\n    print(\"Sending NOTIFY_SOCKET check (silently fails if not running under systemd)\")\n    # Send 'READY=1' to signal that the service is initialized\n    notifier.notify(\"READY=1\")\n    print(\"Service ready. Working...\")\n\n    for i in range(1, 4):\n        status_message = f\"STATUS=Working on task {i} of 3...\"\n        print(status_message)\n        notifier.notify(status_message)\n        time.sleep(2) # Simulate work\n\n    # Send 'STOPPING=1' or just exit (systemd can infer STOPPING upon exit)\n    print(\"Service finished work. Sending STOPPING=1.\")\n    notifier.notify(\"STOPPING=1\")\n\nif __name__ == \"__main__\":\n    main()","lang":"python","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}