#

Monday, June 30, 2025

Working with NAPALM Library in Python for Network Engineers

When retrieving show command outputs, both Scrapli and NAPALM libraries can do pretty much the same thing but Scapli is sending the exact command where NAPALM is using a common command to get the same type of information from different platforms. As an example, NAPALM getter like "get_bgp_neighbors" will retrieve the bgp neighbor information from Cisco, Juniper or any other platform which NAPALM supports.

Following table are the platforms which NAPALM supports at the moment.


First we have to install NAPALM library in our environment, mine is Ubuntu.

python3 -m pip install napalm

Following code gets the device details of the device and print it with the default format.





Part of the output will be something like the following..





Converting Results to a Structured Data Format

For this we need to import the "rich" library. If your system does not have it yet, it can be installed by the following commands.

pip install --user rich
pip install rich

Now by using the following additions to the code will provide a more readable output.





It is just importing the rich library and the result is printed as "rprint" instead of normal "print".

If you need to get a specific information our from the above output, it can be done like in the following.


Above outputs the serial number of the device like the following.




If there are multiple devices in a list it's just modifying the list "DEVICES" like the following.




No comments:

Post a Comment