šŸŽ New User? Get 20% off your first purchase with code NEWUSER20 Register Now →
Menu

Categories

10 Python Libraries Every System Administrator Should Know in 2026

10 Python Libraries Every System Administrator Should Know in 2026

Python is the system administrator's secret weapon. With the right libraries, you can automate virtually any infrastructure task. These 10 libraries are essential for every sysadmin who uses Python in their daily work.

1. Paramiko — SSH Automation

Execute commands on remote servers programmatically:

import paramiko

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect("192.168.1.10", username="admin", key_filename="/home/user/.ssh/id_ed25519")

stdin, stdout, stderr = ssh.exec_command("df -h")
print(stdout.read().decode())
ssh.close()

2. psutil — System Monitoring

Get real-time system information — CPU, memory, disk, network:

import psutil

# CPU usage
print(f"CPU: {psutil.cpu_percent(interval=1)}%")

# Memory
mem = psutil.virtual_memory()
print(f"RAM: {mem.percent}% used ({mem.used // (1024**3)}GB / {mem.total // (1024**3)}GB)")

# Disk
for partition in psutil.disk_partitions():
    usage = psutil.disk_usage(partition.mountpoint)
    print(f"{partition.mountpoint}: {usage.percent}% used")

3. Requests — HTTP API Calls

import requests

# Check website status
response = requests.get("https://example.com", timeout=10)
print(f"Status: {response.status_code}")

# API call with authentication
api_response = requests.get(
    "https://api.example.com/servers",
    headers={"Authorization": "Bearer YOUR_TOKEN"}
)
servers = api_response.json()

4. Click — CLI Tool Builder

import click

@click.command()
@click.option("--server", required=True, help="Server hostname")
@click.option("--action", type=click.Choice(["start", "stop", "restart"]))
def manage_server(server, action):
    """Manage remote server services."""
    click.echo(f"Performing {action} on {server}...")

if __name__ == "__main__":
    manage_server()

5. Jinja2 — Configuration Templates

from jinja2 import Template

template = Template("""
server {
    listen {{ port }};
    server_name {{ domain }};
    root {{ webroot }};
}
""")

config = template.render(
    port=443,
    domain="example.com",
    webroot="/var/www/example"
)
print(config)

6. PyYAML — YAML Configuration

import yaml

# Read YAML configuration
with open("config.yml", "r") as f:
    config = yaml.safe_load(f)

# Write YAML
data = {"servers": ["web01", "web02"], "port": 8080}
with open("output.yml", "w") as f:
    yaml.dump(data, f, default_flow_style=False)

7. Schedule — Task Scheduling

import schedule
import time

def check_disk_space():
    print("Checking disk space...")

def backup_database():
    print("Running database backup...")

schedule.every(5).minutes.do(check_disk_space)
schedule.every().day.at("02:00").do(backup_database)

while True:
    schedule.run_pending()
    time.sleep(1)

8. Watchdog — File System Monitoring

from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler

class ConfigChangeHandler(FileSystemEventHandler):
    def on_modified(self, event):
        print(f"Config changed: {event.src_path}")

observer = Observer()
observer.schedule(ConfigChangeHandler(), path="/etc/nginx/", recursive=True)
observer.start()

9. Fabric — Remote Execution

from fabric import Connection

# Execute commands on remote server
c = Connection("web01.example.com", user="admin")
result = c.run("uptime", hide=True)
print(f"Server uptime: {result.stdout.strip()}")

# Deploy application
c.put("deploy.sh", remote="/tmp/deploy.sh")
c.run("bash /tmp/deploy.sh")

10. Rich — Beautiful Terminal Output

from rich.console import Console
from rich.table import Table

console = Console()

table = Table(title="Server Status")
table.add_column("Server", style="cyan")
table.add_column("Status", style="green")
table.add_column("CPU", justify="right")
table.add_column("Memory", justify="right")

table.add_row("web01", "Online", "45%", "62%")
table.add_row("web02", "Online", "38%", "55%")
table.add_row("db01", "Online", "72%", "81%")

console.print(table)

Master these libraries and Python becomes the most powerful tool in your system administration toolkit.

Learn Python for System Administration

Share this article:
Petr Novak
About the Author

Petr Novak

Senior PHP Developer, Backend Engineer, Technology Author

Petr NovƔk is a professional PHP developer and technology author with over 15 years of experience in backend development, web applications, and server-side programming.

He specializes in building fast, secure, and scalable PHP-based systems, including custom web applications, APIs, and content-driven platforms. His exp...

PHP Development Backend Development REST APIs MySQL Web Security

Stay Updated

Subscribe to our newsletter for the latest tutorials, tips, and exclusive offers.