This lesson is part of the Network Configuration with Scrapli Course.
In this lesson, we will cover:
- The main Scrapli components.
- How to connect to a device.
- How to interact with a device.
- How to close a device connection.
- The Scrapli context manager.
You can find the scripts and code for this lesson within the Scrapli repo under the directory: 002_scrapli_core/001_basics/.
Scrapli Core Components
Scrapli Core is built upon 3 key components – driver, channel and transport.
- Driver – provides the API/interface to the user. In other words, it is the driver that the user interacts with via a set of common (vendor agnostic) methods.
- Channel – resides between the driver and transport components. Performs operations such as sending commands and prompting handling.
- Transport – provides a common interface for which the channel can read/write based on the implemented transport type (
ssh2
,paramiko
, etc). The transport type is configured using transport plugins.

Connecting to a Device
The full code for this section is located here: scrapli_basic.py
Let’s now dive into some code and connect to one of the devices within the lab. First we define the connection variables in a dict()
, which we then pass to instantiate our driver class.
The platform
specifies the driver that will be used. The available platforms are:
- arista_eos
- cisco_iosxe
- cisco_iosxr
- cisco_nxos
- juniper_junos
Once done, we open a connection to the device via open()
. Here is an example:
Note: Once you enter the following code, no output will be returned. This is expected. How we work with our device connection will make more sense as we work through the following sections.
import os
from dotenv import load_dotenv
from rich import print
from scrapli import Scrapli
load_dotenv()
# Create device dict()
device = {
"host": "172.29.151.1",
"auth_username": os.getenv("LAB_USERNAME"),
"auth_password": os.getenv("LAB_PASSWORD"),
"auth_strict_key": False,
"platform": "cisco_nxos",
}
# Instantiate Scrapli driver with device dict()
conn = Scrapli(**device)
# Open connection to device
conn.open()