Technology / Networking

5 Top Free Python Libraries for Network Automation

by John McGovern
5 Top Free Python Libraries for Network Automation picture: A
Follow us
Updated on August 30, 2024

Within the past few years, network automation has exploded in popularity. As a result, an ever-increasing supply of tools is available to help implement automated network configuration and change management. 

Having such a broad array of tools available is fantastic, but it also feels overwhelming and intimidating. To help simplify this, we’ve identified the top five free Python libraries for network automation both in this article and YouTube video:

All of these libraries are sufficiently mature, well-tested, and have strong support within the automation community. In addition to the libraries listed here, there are also some great Python courses to get you started. 

So, let's dig in.

1. Netmiko

Netmiko is an exceptional Python library developed by Kirk Byers designed to act as an abstraction layer over the Paramiko Python implementation of the SSHv2 protocol. In effect, Netmiko is Paramiko reimagined and adapted to interact with networking devices specifically. 

In real terms, Netmiko has been programmed to be aware of the quirks of networking devices and subsequently hides these lower-level details from the automation engineer.

For example, Netmiko understands that when issuing a configuration change to a Cisco device, all commands sent must first begin with an elevation to Global Configuration mode. Thus, it will automatically issue a "configure terminal" on your behalf. These seemingly small details drastically reduce the complexity of your automation scripts.

Moreover, Netmiko tightly integrates with parsing solutions such as TextFSM and Genie, allowing you to return the output of your show commands as structured data.

2. NAPALM

NAPALM is a Python library developed by David Barroso. It has been carefully written to simplify automated interactions with networking devices regardless of operating system through the use of a unified API. NAPALM has many great features, but my favorite is its "Getter" concept.

Suppose, for example, you wanted to pull BGP Neighbor information from your network. Now, if all your devices are Cisco IOS, you could simply use Netmiko to issue a "show ip bgp neighbor" and retrieve that information quickly. However, what if your network was 1/3rd Cisco, 1/3rd Juniper, and 1/3rd Arista?

Using NAPALM Getters, you can pull all of that information simply by issuing the vendor-agnostic command "get_bgp_neighbors." Under the hood, NAPALM will issue the appropriate platform-specific show commands to each device and present that output back to you in a standardized format structured in JSON.

3. Genie

Genie is a Python library (pyATS) developed for automated network testing. It's recommended that anyone new to network automation learn how to use the Genie CLI. In my opinion, there is no better "bang for your buck" in the world of automation today. 

It is simple to use and immediately grants the engineer an incredible level of insight into the state of their network. Using the Genie CLI, engineers can essentially capture and compare different snapshots of the network state and run an automated comparison to identify exactly what has changed.

Let's imagine you were running OSPF within your network. By issuing the Genie CLI command "genie learn ospf," Genie will automatically run a massive volume of different OSPF-specific show commands and collate that information to document all of the OSPF details running within the network. Now, if we assume later down line connectivity in some part of the network was suddenly lost. Through reissuing the "genie learn ospf" command, the current OSPF state will be relearned, thus enabling Genie to compare the current broken state to the original state.

Subsequently, Genie will identify all relevant changes and return a highly targeted summary of items to begin troubleshooting to the engineer. This feature is one that any engineer, even those with no programming experience, can learn to use within one day of training and will continually optimize and simplify their network troubleshooting.

4. NCClient

NCClient is a Python library written to simplify scripting and automation over the NETCONF protocol. Modern automation aims to interact with networking devices via APIs rather than the Command Line Interface. NETCONF is feature-rich and can exact granular control over the network, lock a device's configuration datastore, conduct full-operation configuration replacements, and much more.

The XML-based protocol can be somewhat complex to use, particularly for beginners. However, NCClient and its "Manager" function simplifies this by enabling an API for RPC operations as method calls with support for both Subtree and Xpath filtering. As such, NCClient has become the standard way of interacting with the NETCONF protocol and an essential Python library for the modern network automation engineer.

5. Requests

RESTCONF is a lightweight, stateless HTTP-based protocol and has burst onto the scene as the newer and simpler cousin of NETCONF. As RESTCONF's presence gradually increases, you're going to hear more and more about the Python Requests library. The Requests library abstracts many of the complexities of making HTTP requests behind a simple API and offers several built-in methods to retrieve or push data to a REST-based API, such as GET or POST requests.

For each method, Requests returns back a "response" object for inspection. Included in this object are many extremely useful attributes, such as the returned Status Code and the ability to easily raise exceptions upon failure via the raise_for_status() object. If you're going to be writing Python scripts to automate your network over RESTCONF, you're going to be importing the Requests library.

Bonus Tool: Ansible

While not strictly a Python library, Ansible is an invaluable open-source automation tool that simplifies network automation, configuration management, and application deployment. Its agentless architecture requires no additional software on target devices, streamlining automation across diverse environments. 

Ansible's extensive module library and straightforward YAML playbooks make it user-friendly and highly customizable for complex network tasks. By leveraging Python for custom modules and inventory scripts, Ansible provides flexibility and scalability in managing network infrastructure. Its robustness and ease of use make it a must-have tool for network automation.

Final Thoughts

There are so many Python-based projects bursting on the scene. I encourage you to be adventurous and explore the landscape. That said, if you're simply looking to find tools that are stable, effective, and efficient, these five Python libraries are all tried and true. All of them represent the very best Python library-based network automation options available on the market.

Explore all the Python courses CBT Nuggets has to offer. 


Ultimate Networking Cert Guide

By submitting this form you agree to receive marketing emails from CBT Nuggets and that you have read, understood and are able to consent to our privacy policy.


Don't miss out!Get great content
delivered to your inbox.

By submitting this form you agree to receive marketing emails from CBT Nuggets and that you have read, understood and are able to consent to our privacy policy.

Recommended Articles

Get CBT Nuggets IT training news and resources

I have read and understood the privacy policy and am able to consent to it.

© 2024 CBT Nuggets. All rights reserved.Terms | Privacy Policy | Accessibility | Sitemap | 2850 Crescent Avenue, Eugene, OR 97408 | 541-284-5522