Reference library

Automation & scripting

CLI tools, scheduled jobs, filesystem tasks, and glue scripts that save time.

3 matches
Automation & scripting medium

How to Detect Network Interface Changes in Python

Monitor active network interfaces and print a message when an interface is added or removed using psutil and socket.

network monitoring psutil
Python
import socket
import psutil
import time

def get_network_interfaces():
    """Return a set of currently active interface names."""
    active_ifaces = set()
    for iface, addrs in psutil.net_if_addrs().items():
        for addr in addrs:
            if addr.family == socket.AF_INET:  # IPv4 address present
          …
44 0 Open
Automation & scripting easy

Monitor Disk Usage and Alert in Python

A Python script that checks disk usage percentage against a threshold and returns an ALERT or OK message with free space details.

disk monitoring shutil
Python
import shutil
import os

def check_disk_usage(path="/", threshold=85.0):
    usage = shutil.disk_usage(path)
    percent_used = (usage.used / usage.total) * 100
    
    if percent_used > threshold:
        return (f"ALERT: Disk usage at {percent_used:.1f}% on {path} "
                f"(exceeds {threshold}% threshold…
12 0 Open
Automation & scripting easy

Post a message to a Slack webhook in Python

Send a message to a Slack webhook endpoint using the standard library's urllib.request, handling the POST request and response cleanly.

slack webhook urllib
Python
import json
from urllib import request

def post_to_slack(webhook_url: str, message: str) -> dict:
    payload = json.dumps({"text": message}).encode("utf-8")
    req = request.Request(
        webhook_url,
        data=payload,
        headers={"Content-Type": "application/json"},
        method="POST",
    )
    wit…
10 0 Open

Browse by section

Each section groups closely related Python snippets.

Automation & scripting — Python code examples

What you will find here

This page collects automation & scripting snippets — short, copy-ready Python you can paste into our free online IDE and run without installing anything. Each sample includes a plain-English explanation and the full source code.

Samples vs tutorials and challenges

Samples are quick reference — one concept per page. For step-by-step teaching, use our Python tutorials. To test yourself, try quizzes or coding challenges. Clean up style with the Python formatter.