systemd/python-systemd is tracked by TopGit as an open-source project, with 521 stars on GitHub, written primarily in C. Python wrappers for systemd functionality
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
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:
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(datetime.now() - timedelta(minutes=20))
for entry in j:
print(entry['MESSAGE'])
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 = datetime.now() - timedelta(minutes=50)
until = datetime.now() - timedelta(minutes=10)
j.seek_realtime(since)
for entry in j:
if entry['__REALTIME_TIMESTAMP'] > until:
break
print(entry['MESSAGE'])
Show explanations of log messages alongside entries (journalctl -x):
from systemd import journal
j = journal.Reader()
for entry in j:
print("MESSAGE: ", entry['MESSAGE'])
try:
print("CATALOG: ", j.get_catalog())
except:
pass
Show entries by a specific executable (journalctl /usr/bin/vim):
from systemd import journal
j = journal.Reader()
j.add_match('_EXE=/usr/bin/vim')
for entry in j:
print(entry['MESSAGE'])
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()
j.add_match('_TRANSPORT=kernel')
for entry in j:
print(entry['MESSAGE'])
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()
j.add_match('_EXE=/usr/bin/vim')
j.seek_tail()
for entry in j:
print(entry['MESSAGE'])
Notes
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:
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.
Documentation
Online documentation can be found at freedesktop.org
To build it locally run:
ninja -C build html
Or use any other builder, see man sphinx-build for a list. The compiled docs will be e.g. in build/html.
Viewing Output
Quick way to view output with all fields as it comes in:
Yes — systemd/python-systemd ships under the LGPL-2.1 license, which makes its source code freely readable (and, depending on license terms, forkable and reusable). Source: github.com/systemd/python-systemd.
What is systemd/python-systemd?
systemd/python-systemd (systemd/python-systemd) is a C project on GitHub. From the project's own README: Python wrappers for systemd functionality
Where do I read more about systemd/python-systemd?
This TopGit page is a snapshot — the READ ME tab shows the project's own README content (links stripped, images preserved). The GitHub repository at github.com/systemd/python-systemd is the definitive source.
Read full README in the tab above.
Curious whether python-systemd is right for you?
Let ChatGPT, Claude, or Perplexity look into it — click below and see what AI actually says about python-systemd.