High-level Python client for systemd user services: unit management, journal reading, sync + async
Project description
systemd-client
High-level Python client for systemd user services. Async-first with sync wrappers, subprocess + optional D-Bus backends, CLI included.
English Documentation · Documentacion en Espanol
Features
- Async + Sync API —
AsyncSystemdClientandSystemdClientwith identical interfaces - Unit management — list, status, start, stop, restart, reload, enable, disable, mask, unmask
- Journal reader — query with filters (unit, priority, time range, grep) and real-time follow
- Pluggable backends — subprocess (default, zero deps) or D-Bus via dasbus
- Typed models — frozen dataclasses with full annotations, optional Pydantic support
- CLI —
systemd-clientcommand with table and JSON output - Modern Python — 3.11+, StrEnum, slots, PEP 561 typed
Install
pip install systemd-client
Optional extras:
pip install systemd-client[dbus] # D-Bus backend via dasbus
pip install systemd-client[pydantic] # Pydantic model variants
pip install systemd-client[all] # Everything
Quick Start
Sync
from systemd_client import SystemdClient
client = SystemdClient()
# List services
for unit in client.list_units(unit_type="service"):
print(f"{unit.name}: {unit.active_state} ({unit.sub_state})")
# Manage units
client.restart("my-app.service")
status = client.status("my-app.service")
print(f"PID: {status.main_pid}, State: {status.active_state}")
# Journal
entries = client.journal("my-app.service", lines=50, since="1h ago")
for entry in entries:
print(f"[{entry.priority}] {entry.message}")
# Follow journal in real-time
for entry in client.journal_follow("my-app.service"):
print(entry.message)
Async
import asyncio
from systemd_client import AsyncSystemdClient
async def main():
client = AsyncSystemdClient()
units = await client.list_units(unit_type="service")
await client.restart("my-app.service")
async for entry in client.journal_follow("my-app.service"):
print(entry.message)
asyncio.run(main())
CLI
systemd-client list # List all units
systemd-client list --type service # List services only
systemd-client status my-app.service # Unit status
systemd-client restart my-app.service # Restart
systemd-client journal -u my-app.service -n 50 # Last 50 log lines
systemd-client journal -u my-app.service --follow # Follow logs
systemd-client --json list # JSON output
Architecture
Your Application
|
+-- SystemdClient (sync)
| |
+-- AsyncSystemdClient (async)
|
+-- SubprocessBackend ---- systemctl --user ----> systemd
| (default)
+-- DBusBackend ---------- D-Bus session bus ---> systemd
| (optional, dasbus)
+-- AsyncJournalReader --- journalctl --user ---> journal
API Reference
| Method | Return | Description |
|---|---|---|
list_units(unit_type?, state?) |
list[UnitInfo] |
List user units |
status(unit) |
UnitStatus |
Detailed status |
start(unit) |
None |
Start unit |
stop(unit) |
None |
Stop unit |
restart(unit) |
None |
Restart unit |
reload(unit) |
None |
Reload unit |
enable(unit) |
EnableResult |
Enable unit |
disable(unit) |
EnableResult |
Disable unit |
mask(unit) / unmask(unit) |
EnableResult |
Mask/unmask |
is_active(unit) |
bool |
Check active |
is_enabled(unit) |
bool |
Check enabled |
is_failed(unit) |
bool |
Check failed |
daemon_reload() |
None |
Reload daemon |
journal(unit?, lines?, since?, until?, priority?, grep?) |
list[JournalEntry] |
Query journal |
journal_follow(unit?, lines?, priority?) |
Iterator[JournalEntry] |
Follow journal |
Examples
See the examples/ directory for 15 ready-to-use scripts covering:
- Listing and monitoring services
- Start/stop/restart/enable operations
- Journal queries and real-time follow
- Health checks and failed unit reports
- Async concurrent operations
- Deploy workflows
- Batch operations
Requirements
- Python >= 3.11
- Linux with systemd
systemctlandjournalctlon PATH
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file systemd_client-0.1.1.tar.gz.
File metadata
- Download URL: systemd_client-0.1.1.tar.gz
- Upload date:
- Size: 36.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3b17de1b51a16dff0e3645d07c91b5d45c25305b518b2f65b504653ebaf9c0d7
|
|
| MD5 |
d08d0ddd0b5b5ddbec73a4d67e39910e
|
|
| BLAKE2b-256 |
54ad8b720da81d04556be643603a3ded52e3e699e6da31a7cb3b2ac6214f2454
|
Provenance
The following attestation bundles were made for systemd_client-0.1.1.tar.gz:
Publisher:
publish.yml on kalexnolasco/systemd-client
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
systemd_client-0.1.1.tar.gz -
Subject digest:
3b17de1b51a16dff0e3645d07c91b5d45c25305b518b2f65b504653ebaf9c0d7 - Sigstore transparency entry: 1203288508
- Sigstore integration time:
-
Permalink:
kalexnolasco/systemd-client@fedf2a377f7f0ba553e2bf6f4fd43c13178c1d1e -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/kalexnolasco
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@fedf2a377f7f0ba553e2bf6f4fd43c13178c1d1e -
Trigger Event:
release
-
Statement type:
File details
Details for the file systemd_client-0.1.1-py3-none-any.whl.
File metadata
- Download URL: systemd_client-0.1.1-py3-none-any.whl
- Upload date:
- Size: 24.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
057101c7eb34bbb11bdeda7be38eafec5ad0d83ec40b6f3c138a0f80c97d9d74
|
|
| MD5 |
b5c647f48499ec185d6b7317c7994e67
|
|
| BLAKE2b-256 |
a6752ae51f02fcd417b9d4d24071be4d2264fffe7abacd9b177cf149e0c8b1e2
|
Provenance
The following attestation bundles were made for systemd_client-0.1.1-py3-none-any.whl:
Publisher:
publish.yml on kalexnolasco/systemd-client
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
systemd_client-0.1.1-py3-none-any.whl -
Subject digest:
057101c7eb34bbb11bdeda7be38eafec5ad0d83ec40b6f3c138a0f80c97d9d74 - Sigstore transparency entry: 1203288510
- Sigstore integration time:
-
Permalink:
kalexnolasco/systemd-client@fedf2a377f7f0ba553e2bf6f4fd43c13178c1d1e -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/kalexnolasco
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@fedf2a377f7f0ba553e2bf6f4fd43c13178c1d1e -
Trigger Event:
release
-
Statement type: