#

Wednesday, June 25, 2025

Working with Scrapli Library in Python for Network Engineers

Scrapli is a widely used library in Python for network related work. In this post let's see how it can be used to do very simple taks. Following link gives more information on Scrapli as it is the official site.

https://carlmontanari.github.io/scrapli/

First of all installing Scrapli..

python3 -m pip install scrapli

Following is the router I used to access in EVE-NG and the IP address of E0/0 interface is 192.168.1.13


Note that interface is bridged to the physical port of the VM and it is in the same LAN as my Devnet PC (Ubuntu)
















I had to change the ssh_config file of Ubuntu to match the older Ciphers like the following and auth_secondary which is the enable password needed to be configured in order to access the devices in EVE-NG.

Following white colored text were the text I needed to add.




















Following was the output..





Converting Results to a Structured Data Format

This can be using one of the following solutions.

1. Text fsm
2. Genie

I will perform the following example by Textfsm. For that we need to install Textfsm templates to Scrapli library.

use following command in cli;

python3 -m pip install scrapli[textfsm]

Following code will get the "show version" output to the "JSON" structured format.


Output:-

















Configuring Devices with Scrapli

Following example will configure ospf process and ospf router id using Scrapli.














When this code is run, configured commands will be shown as the output as per the last line also.
Note that the commands are sent as a list and will be configured as line by line and no need to send "configure terminal" command as it will be taken care by the library.






If the Config commands are in a file;















Output will show the commands which were in the file;






No comments:

Post a Comment