Skip to content
A pure Python implementation of systemd's service notification protocol (sd_notify)
Branch: master
Clone or download
Brett Bethke
Brett Bethke Bump version to v0.3.2
Latest commit d349a64 Aug 3, 2017
Type Name Latest commit message Commit time
Failed to load latest commit information.

systemd Service Notification

This is a pure Python implementation of the systemd sd_notify protocol. This protocol can be used to inform systemd about service start-up completion, watchdog events, and other service status changes. Thus, this package can be used to write system services in Python that play nicely with systemd. sdnotify is compatible with both Python 2 and Python 3.

Normally the SystemdNotifier.notify method silently ignores exceptions (for example, if the systemd notification socket is not available) to allow applications to function on non-systemd based systems. However, setting debug=True will cause this method to raise any exceptions generated to the caller, to aid in debugging.


pip install sdnotify

Example Usage

This is an example of a simple Python service that informs systemd when its startup sequence is complete. It also sends periodic status updates to systemd, which can be viewed with systemctl status test.

import sdnotify
import time

print("Test starting up...")
# In a real service, this is where you'd do real startup tasks
# like opening listening sockets, connecting to a database, etc...
print("Test startup finished")

# Inform systemd that we've finished our startup sequence...
n = sdnotify.SystemdNotifier()

count = 1
while True:
	print("Running... {}".format(count))
	n.notify("STATUS=Count is {}".format(count))
	count += 1


Description=A test service written in Python

# Note: setting PYTHONUNBUFFERED is necessary to see the output of this service in the journal
# See

# Adjust this line to the correct path to
ExecStart=/usr/bin/python /path/to/

# Note that we use Type=notify here since will send "READY=1"
# when it's finished starting up
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.