Python Systemd

Python wrappers for systemd functionality
Alternatives To Python Systemd
Project NameStarsDownloadsRepos Using ThisPackages Using ThisMost Recent CommitTotal ReleasesLatest ReleaseOpen IssuesLicenseLanguage
Fhs Install V2ray4,705
7 months ago11gpl-3.0Shell
Bash script for installing V2Ray in operating systems such as Debian / CentOS / Fedora / openSUSE that support systemd
a year ago14otherPython
A quick way into a systemd "bottle" for WSL
Qbittorrent Nox Static795
10 days agoapache-2.0Shell
A bash script which builds a fully static qbittorent-nox binary with current dependencies to use on any Linux OS
723 days ago43May 28, 202112mitRuby
Package any app into deb or rpm packages, using heroku buildpacks
Ansible Role Hardening439
3 hours ago12apache-2.0Jinja
Ansible role to apply a security baseline. Systemd edition.
Python Systemd405242266 months ago3March 26, 201711lgpl-2.1C
Python wrappers for systemd functionality
a year ago7Shell
A easily command interaction manager for v2ray
a month ago11gpl-2.0C
An Advanced Linux RAM Drive and Caching kernel modules. Dynamically allocate RAM as block devices. Use them as stand alone drives or even map them as caching nodes to slower local disk drives. Access those volumes locally or export them across an NVMe Target network. Manage it all from a web API.
Ufw Docker Automated153
4 months ago11December 27, 20214apache-2.0Go
Manage docker containers firewall with UFW!
3 years agoShell
El Psy Congroo!
Alternatives To Python Systemd
Select To Compare

Alternative Project Comparisons


Python module for native access to the systemd facilities. Functionality is separated into a number of modules:

  • systemd.journal supports sending of structured messages to the journal and reading journal files,
  • systemd.daemon wraps parts of libsystemd useful for writing daemons and socket activation,
  • systemd.id128 provides functions for querying machine and boot identifiers and a lists of message identifiers provided by systemd,
  • systemd.login wraps parts of libsystemd used to query logged in users and available seats and machines.


This module should be packaged for almost all Linux distributions. Use

On Fedora:

dnf install python3-systemd

On Debian/Ubuntu/Mint:

apt update
apt install python3-systemd

On openSUSE and SLE:

zypper in python3-systemd

On Arch:

pacman -Sy python-systemd

The project is also available on pypi as systemd-python:


To build from source

On CentOS, RHEL, and Fedora:

dnf install git python3-pip gcc python3-devel systemd-devel
pip3 install 'git+'

On Debian or Ubuntu:

apt install libsystemd-{journal,daemon,login,id128}-dev gcc python3-dev pkg-config


Quick example:

from systemd import journal
journal.send('Hello world')
journal.send('Hello, again, world', FIELD2='Greetings!', FIELD3='Guten tag')
journal.send('Binary message', BINARY=b'\xde\xad\xbe\xef')

There is one required argument the message, and additional fields can be specified as keyword arguments. Following the journald API, all names are uppercase.

The journald sendv call can also be accessed directly:

from systemd import journal
journal.sendv('MESSAGE=Hello world')
journal.sendv('MESSAGE=Hello, again, world', 'FIELD2=Greetings!',
               'FIELD3=Guten tag')
journal.sendv('MESSAGE=Binary message', b'BINARY=\xde\xad\xbe\xef')

The two examples should give the same results in the log.

Reading from the journal is often similar to using the journalctl utility.

Show all entries since 20 minutes ago (journalctl --since "20 minutes ago"):

from systemd import journal
from datetime import datetime, timedelta
j = journal.Reader()
j.seek_realtime( - timedelta(minutes=20))
for entry in j:

Show entries between two timestamps (journalctl --since "50 minutes ago" --until "10 minutes ago"):

from systemd import journal
from datetime import datetime, timedelta
j = journal.Reader()
since = - timedelta(minutes=50)
until = - timedelta(minutes=10)
for entry in j:
  if entry['__REALTIME_TIMESTAMP'] > until:

Show explanations of log messages alongside entries (journalctl -x):

from systemd import journal
j = journal.Reader()
for entry in j:
    print("MESSAGE: ", entry['MESSAGE'])
        print("CATALOG: ", j.get_catalog())

Show entries by a specific executable (journalctl /usr/bin/vim):

from systemd import journal
j = journal.Reader()
for entry in j:
  • Note: matches can be added from many different fields, for example entries from a specific process ID can be matched with the _PID field, and entries from a specific unit (ie. journalctl -u systemd-udevd.service) can be matched with _SYSTEMD_UNIT. See all fields available at the systemd.journal-fields docs.

Show kernel ring buffer (journalctl -k):

from systemd import journal
j = journal.Reader()
for entry in j:

Read entries in reverse (journalctl _EXE=/usr/bin/vim -r):

from systemd import journal
class ReverseReader(journal.Reader):
    def __next__(self):
        ans = self.get_previous()
        if ans:
            return ans
        raise StopIteration()

j = ReverseReader()
for entry in j:


  • Unlike the native C version of journald's sd_journal_send(), printf-style substitution is not supported. Perform any substitution using Python's f-strings first (or .format() or the % operator).
  • A ValueError is raised if sd_journald_sendv() results in an error. This might happen if there are no arguments or one of them is invalid.

A handler class for the Python logging framework is also provided:

import logging
from systemd import journal
logger = logging.getLogger('custom_logger_name')
logger.warning("Some message: %s", 'detail')

libsystemd version compatibility

This module may be compiled against any version of libsystemd. At compilation time, any functionality that is not available in that version is disabled, and the resulting binary module will depend on symbols that were available at compilation time. This means that the resulting binary module is compatible with that or any later version of libsystemd. To obtain maximum possible functionality, this module must be compile against suitably recent libsystemd.


Online documentation can be found at

To build it locally run:

make sphinx-html

Or use any other builder, see man sphinx-build for a list. The compiled docs will be e.g. in docs/html.

Viewing Output

Quick way to view output with all fields as it comes in:

sudo journalctl -f --output=json

Test Builds (for Development)

python build_ext -i
>>> from systemd import journal
>>> journal.send("Test")

Build Status

Popular Systemd Projects
Popular Debian Projects
Popular Operations Categories

Get A Weekly Email With Trending Projects For These Categories
No Spam. Unsubscribe easily at any time.