A Python script usually spends very little time doing actual Python work. Most of the actual work comes from libraries that know how to connect to network devices and do the work. They interact with APIs. Once you understand what each library does, you can spend less time writing code and more time solving network problems.
Here are the libraries I think every network engineer should become familiar with.
Netmiko
It provides a simple way to connect to routers, switches, and firewalls over SSH without dealing with the complexity of building SSH sessions yourself. Instead of opening an SSH client and logging into fifty routers one at a time, a Netmiko script can connect to each device, run commands, collect the output, and disconnect. Configuration backups, software version audits, interface reports, and BGP verification scripts are all common Netmiko projects.
https://python-automation-book.readthedocs.io/en/1.0/12_netmiko/01_netmiko.html
NAPALM
NAPALM stands for Network Automation and Programmability Abstraction Layer with Multivendor support.
One of its biggest advantages is that the same Python code can work across multiple vendors. If your network includes Cisco, Juniper, Arista, or MikroTik devices, NAPALM provides a consistent way to retrieve information such as interface status, routing tables, or environmental data without writing vendor-specific code for every platform. That makes it useful when your network is built from equipment made by several manufacturers.
https://napalm.readthedocs.io/en/latest
Nornir
Nornir helps organize larger automation projects by keeping track of your device inventory, running tasks across many devices at the same time, and separating your automation into reusable components.
Instead of one large script that connects to hundreds of routers, you build smaller tasks that Nornir coordinates. If you plan to automate an ISP or enterprise network, Nornir is worth learning.
https://nornir.readthedocs.io/en/latest
Paramiko
If you need complete control over an SSH session, Paramiko gives you that flexibility. You can build custom authentication methods, transfer files over SCP or SFTP, or automate systems that Netmiko does not directly support.
Most network engineers will spend more time using Netmiko than Paramiko, but understanding what it does helps when you run into devices or systems that require custom SSH handling.
Requests
Firewalls, wireless controllers, cloud platforms, monitoring systems, and IPAM software often expose REST APIs. The Requests library makes it easy to send HTTP GET, POST, PUT, and DELETE requests to those systems. Not every device is managed through SSH anymore.
If you have worked with platforms like LibreNMS, NetBox, Meraki, Palo Alto, Cloudflare, or PowerDNS, there is a good chance a Python script using Requests can automate much of the work.
https://pypi.org/project/requests
Pandas
Pandas makes it easy to organize data into tables, filter results, sort values, compare reports, and export everything into CSV or Excel files.
For example, you might collect interface utilization from every router in your network. Pandas can sort the results from highest utilization to lowest so you immediately know which circuits deserve attention.
TextFSM
Commands like show interfaces, show ip bgp summary, or show version return large blocks of text. TextFSM converts that text into structured data that Python can work with.
Instead of searching hundreds of lines for an interface status, your script can reference a field such as interface_status or serial_number directly.
https://pypi.org/project/textfsm
Jinja2
Only a few values change between devices, such as hostnames, IP addresses, VLAN IDs, or BGP AS numbers. Jinja2 lets you create a configuration template with placeholders for those values.
Your Python script fills in the variables and generates complete configurations automatically. That reduces typing mistakes and keeps deployments consistent across every router or switch.
https://pypi.org/project/Jinja2
Which Library Should You Learn First?
If you are just getting started, I would begin with Netmiko.
Once you are comfortable connecting to devices, learn Requests so you can work with REST APIs. Add Pandas when you need reports, then look at TextFSM to turn CLI output into structured data. Jinja2 becomes valuable once you start deploying larger numbers of devices, and Nornir makes sense when your automation projects begin growing beyond a few simple scripts.
You do not need to master all of these libraries before writing useful automation. Learning one library at a time is usually enough to replace repetitive tasks that consume hours every week.
j2networks family of siteshttps://j2sw.com
https://startawisp.info
https://indycolo.net
#packetsdownrange #routethelight
Discover more from Justin Wilson (j2sw)
Subscribe to get the latest posts sent to your email.