DevNetnetwork programming
Top 6 Python modules for network programming
October 17, 2020by masterus3r
0 Comments
In the track of both Network Automation and programming using python, there is some necessary modules you should know. If you have already visited “Necessary python modules for DevNet and Cisco Programming” ,perhaps you also know these 6 modules.
List of Top 6 python modules for network programming :
 Netmiko is simple and multi-vendor SSH connection to network devices and certainly one the greatest modules for network programming. In addition It is based on paramiko but hide paramiko’s complexity. we have written about differences between Netmiko and Paramiko before (Netmiko vs Paramiko). Additionally Netmiko supports only SSHv2 (not v1).
Finally here is an example of Netmiko :
In conclusion of example above, we passed username (cisco) and password (123456) to cisco NXos device (172.16.0.1) and executed “show ip int br” command. Obviously the result of Python code is , “SHOW IP INTERFACE BRIEF” output.
Similarly, in case of different vendors , you can pass the variable “device_type” to specify vendor.
Also you can read more about Netmiko in url below :
PySNMP is a cross-platform and also pure-Python SNMP engine implementation. In detail it features fully-functional SNMP engine capable to act in Agent/Manager/Proxy roles, talking SNMP v1/v2c/v3 protocol versions over IPv4/IPv6 and other network transports. (Based on official site)
For instance here is an example :
Also you can learn about pysnmp usage in cisco devices :
NAPALM stands on Network Automation and Programmability Abstraction Layer with Multivendor support and is another multivendor (Obviously!) python library for automation.
Until now and at the time of writing, it supports following devices (read more):
Of course we can choose which driver we want to work around and import.
The following is an example of Napalm :
Furthermore you can follow NAPALM articles and examples :
Nornir is an automation framework created in python and it requires Python 3.6.2 or higher.It provides an abstraction for inventory (hosts and groupd) and concurrent task execution. Shortly the greatest advantage is that it’s very fast due to use threads. Besides you can find more information here.
Nornir is great and allows you to utilise already tried and tested Python libraries such as Netmiko and NAPALM.
However you can learn more :
Whether you are a network programming or programmer , you need to test codes you’ve written. Unittest is a unit testing framework and includes both testing framework and test runner.
Although we have explained it in detail:
Finally , pyATS is an end-to-end testing ecosystem, specializing in data-driven and reusable testing, and engineered to be suitable for Agile, rapid development iterations. Extensible by design, pyATS enables developers start with small, simple and linear test cases, and scale towards large, complex and asynchronous test suites.
However pyATS is initially developed internally in Cisco, and is now available to the general public starting late 2017 through Cisco DevNet. Visit the pyATS home page at https://developer.cisco.com/site/pyats/