Fluent Python SDK and shell for Linux server operations
Project description
ServerKit
A Python design exercise: Linux server resources as fluent, chainable objects.
ServerKit wraps host inspection (processes, memory, logs, disk, services, …) behind a Server facade, collection filters, and persisted workflows. It ships as a library and a small REPL — not as a production orchestration tool.
pip install "serverkit[rich]"
serverkit --version
Docs: User guide · Examples · PyPI
Why we Built This
We wanted to practice object-oriented API design on a real domain: Linux server operations.
Most admin work is expressed as shell pipelines and one-off scripts. ServerKit asks a different question: what if processes, logs, and memory were typed collections with fluent filters and explicit terminal methods?
Goals
- Model host resources as composable objects, not string commands
- Keep local and remote behind the same facade (
Server/RemoteServer) - Persist multi-step checks as versioned JSON workflows
- Expose the SDK through a thin REPL for fast feedback
Non-goals
- Replacing Ansible, Fabric, Kubernetes, or production incident tooling
- Running arbitrary shell from an LLM (the optional AI layer routes to SDK calls only)
This repository is a portfolio piece demonstrating API shape, abstraction boundaries, and developer experience — not a claim to production-scale ops coverage.
Live Demo
~75s walkthrough: REPL → memory → process filters → save workflow → run locally → run on a remote host via SSH.
You'll see:
- Host memory and process collections queried through the REPL
- A workflow composed in one line and saved to
~/.serverkit/workflows/ - The same workflow executed on a remote host without changing the JSON
Recording steps: docs/demo/DEMO.md
Architecture
flowchart TB
subgraph clients [Clients]
REPL[serverkit REPL]
PY[Python scripts]
end
subgraph facade [Facade layer]
SRV[Server]
REM[RemoteServer]
PROTO[ServerFacade Protocol]
end
subgraph domain [Domain collections]
PROC[ProcessCollection]
LOG[LogFile]
WF[Workflow engine]
end
subgraph infra [Infrastructure]
OS[psutil / system tools]
SSH[Paramiko SSH]
end
REPL --> SRV
REPL --> REM
PY --> SRV
PY --> REM
SRV --> PROTO
REM --> PROTO
PROTO --> PROC
PROTO --> LOG
PROTO --> WF
SRV --> OS
REM --> SSH
| Layer | Responsibility |
|---|---|
| Facade | Server / RemoteServer — single entry point per host (serverkit/core/server.py, serverkit/core/protocol.py) |
| Collections | Eager snapshots + fluent filters + terminal .summarize() / .display() |
| Workflows | JSON schema_version: 2 pipelines; _server injected at runtime for local or remote |
| Shell | Pattern-matched REPL → SDK calls (serverkit/shell/parser.py) |
Key Design Decisions
| Decision | Rationale |
|---|---|
| Facade + Protocol | ServerFacade lets workflows and tests treat local and SSH targets uniformly without duplicating step logic. |
| Fluent collections | Filters apply eagerly on in-memory snapshots; chains read left-to-right; terminal methods make execution explicit. |
| Workflow as composite | Steps are registered strategies (StepFactory); executor walks a shared context dict — easy to add step types without changing the REPL. |
| Thin REPL | Parser maps strings to SDK calls; no embedded Python eval — keeps shell and library boundaries clear. |
| Optional extras | rich, remote, docker, ai as install extras — core SDK stays small; OptionalDependencyError guides installs. |
Tradeoffs we accepted
- Eager snapshots over streaming (simpler mental model; fine for inspection, not for log tailing at scale)
- REPL coverage is a subset of the SDK — scripts are the fully composable surface
- Remote parity is broad but not exhaustive (workflows are authored locally, executed with remote
_server)
Example Usage
REPL — chains map directly to SDK calls:
memory
processes().memory_above(200).sort_by_memory().display()
workflow("audit").processes().memory_above(300).summarize().save()
run audit
Python — same objects, scriptable:
from serverkit import Server
server = Server()
print(server.processes().memory_above(500).sort_by_memory().summarize())
server.workflow("audit").processes().memory_above(500).summarize().save()
server.run("audit")
Remote — Server.connect() returns a facade that implements the same protocol:
with Server.connect("host", user="deploy", key_path="~/.ssh/id_ed25519") as remote:
remote.run("audit") # workflow JSON local; execution uses remote _server
More: examples/ · memory_audit.py · remote_audit.py
Install
pip install "serverkit[rich]" # recommended: SDK + REPL + tables
pip install "serverkit[all]" # + remote, docker, ai
serverkit # interactive shell
Config is created at ~/.serverkit/config.json on first launch. Optional extras, AI, and full REPL reference: User guide.
Documentation
| Guide | Description |
|---|---|
| User guide | Mental model, SDK, REPL, remote, AI, troubleshooting |
| Examples | Runnable sample scripts |
Team
- Anoushka Awasthi (GitHub)
- Aahil Khan
Development
python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
pytest
Integration tests (live OS): pytest -m integration
License
MIT — see LICENSE.
Project details
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 serverkit-0.3.7.tar.gz.
File metadata
- Download URL: serverkit-0.3.7.tar.gz
- Upload date:
- Size: 92.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c1e01f666f3b378dff03334e277b1633cd6703f109598ab96b6e0973087396f5
|
|
| MD5 |
83e4fac1888ef261062bdba0f3051ae1
|
|
| BLAKE2b-256 |
286449791f5070d528473fdb1c30c22e7f9ec677b30057861d31a81803d9b366
|
File details
Details for the file serverkit-0.3.7-py3-none-any.whl.
File metadata
- Download URL: serverkit-0.3.7-py3-none-any.whl
- Upload date:
- Size: 107.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5258c9ee3149fb66635848ec1becaa59f95cd4fe68e5d143e9097b6a65560e4e
|
|
| MD5 |
32c3901dac53285916ca1041e68aea66
|
|
| BLAKE2b-256 |
85738741494e2686dc5d891c13bcf26466b646f75d1e447e1e3fa02b07a9c923
|