Configuring 200 switches by hand is slow and error-prone. Netmiko connects to a device over SSH from Python and runs commands — your first step out of the CLI.
Why: doing the same config on hundreds of devices by hand is slow, inconsistent, and error-prone — automation makes changes fast, repeatable, and reviewable, and lets you treat network config like code. When: automate anything you do more than a couple of times, or across more than a couple of devices. Where: this is exactly the leap that "APIs for Networking" on the roadmap is about.
BY HAND AUTOMATED (code)
SSH to each device, type, one script -> all devices, identically
typo, repeat 200x version-controlled + peer-reviewed
no record of what changed every change logged and diffable
drift creeps in config is consistent and enforceable
Start simple: SSH from Python (Netmiko), then templates, then APIs.Why: Netmiko wraps SSH so you connect to a device with a dictionary and send a command with one call, getting the output back as a string — the simplest possible entry into automation. When: use it to pull "show" output from one or many devices. Where: it supports dozens of platforms via the device_type field.
pip install netmikoWhy: connecting, sending a show command, and printing the result is the template every later script builds on — and it already replaces manual SSH. When: use send_command for show/operational commands. Where: never hard-code passwords in the script; read them from the environment or a secrets manager (covered later).
from netmiko import ConnectHandler
import os
device = {
"device_type": "cisco_ios",
"host": "192.168.1.1",
"username": "admin",
"password": os.environ["NET_PASS"], # from the environment, not hard-coded
}
with ConnectHandler(**device) as conn:
output = conn.send_command("show ip interface brief")
print(output)Why: the real value shows the moment you run the same command across a fleet — a loop over an inventory turns one device into a hundred with no extra effort. When: use it for audits ("show version on everything") and bulk checks. Where: keep going on failure so one unreachable device does not stop the whole run.
from netmiko import ConnectHandler
hosts = ["192.168.1.1", "192.168.1.2", "192.168.1.3"]
base = {"device_type": "cisco_ios", "username": "admin", "password": "..."}
for host in hosts:
try:
with ConnectHandler(host=host, **base) as conn:
print(host, "->", conn.send_command("show version | include uptime"))
except Exception as e:
print(host, "FAILED:", e) # one bad device doesn't stop the run