Python for Network Automation: Netmiko and NAPALM in Practice
Python is essential for the modern network engineer. Netmiko (multi-vendor SSH), NAPALM (unified API), PyEZ (Juniper), and Nornir (Pythonic framework) replace Perl/Expect/Bash. This guide covers the Python network engineering ecosystem in 2026.
Core libraries
Netmiko
- Simple multi-vendor SSH connectivity
- from netmiko import ConnectHandler
- device = { 'device_type': 'cisco_ios', 'host': '10.0.0.1', 'username': 'admin', 'password': 'pass' }
- conn = ConnectHandler(**device)
- output = conn.send_command('show version')
NAPALM
- Unified cross-vendor API
- from napalm import get_network_driver
- driver = get_network_driver('ios')
- dev = driver('10.0.0.1', 'admin', 'pass')
- dev.open()
- facts = dev.get_facts()
- interfaces = dev.get_interfaces_ip()
- dev.close()
PyEZ (Juniper)
- Native Juniper NETCONF/YANG support
- from jnpr.junos import Device
- dev = Device(host='10.0.0.1', user='admin', password='pass')
- dev.open()
- dev.rpc.get_config()
Nornir
- Pythonic framework for large-scale automation
- Hierarchical inventory (vs plain Ansible)
- Native Python parallelization
- Plugins: NAPALM, Netmiko, Jinja2
- Better suited than Ansible for >1000 devices
Requests + REST
- For modern APIs: Meraki, FortiGate, Panorama
- import requests
- r = requests.get('https://api.meraki.com/api/v1/organizations', headers={'X-Cisco-Meraki-API-Key': 'KEY'})
Scapy: packet manipulation
- Craft, send, and capture packets
- Use cases: testing, scanning, and learning
- Example: send a custom ping or test an ACL
Jinja2: templates
- Generate configurations from data
- Integrated with Ansible and also available standalone
- Example: Jinja2 template + YAML → 100 switch configurations
Common use cases
- Configuration backups: Netmiko + cron
- Configuration audits (compliance)
- Dynamic inventory: SNMP scanning + CMDB
- Mass configuration deployment: VLAN, ACL, QoS
- Health checks: post-change validation
- Reports: BGP and OSPF status, CPU, and memory
Tools and IDEs
- VSCode + Python extension
- PyCharm
- Jupyter notebooks for exploration
- Black: formatter
- pylint: linter
Recommended skills
- Python basics: dictionaries, lists, functions, classes
- asyncio: parallel execution
- Git + Gitflow
- REST API + JSON
- Regex for parsing CLI output
- YAML + Jinja2
Training
- Cisco DevNet Associate / Professional
- Python Network Programming (Eric Chou)
- NetworkToCode training courses
- Udemy: Python courses for network engineers
- YouTube: Kirk Byers (Netmiko creator)
Order from OPTINOC
Python network training for teams: 5-day bootcamp. Network automation script mentoring. Quote within 48 hours.
