Getting Started with NetMiko


I started my Python and programming journey by looking at the NetMiko python library. Looking at the code examples and uses that I have seen so far, it seemed to be the most flexible to work with the types of devices I wanted to control.

First steps first, you can find the library here: 

Basic Use Example

From looking through the NetMiko github, there are code examples and a very good example of a basic use case. Let’s start taking a look at that first:


#!/usr/bin/env python
from netmiko import Netmiko
from getpass import getpass
net_connect = Netmiko(

Walking through this script line by line makes a person realize how simply logical this is. Getting into this mindset and beginning to think in this logical manner is a great skill. From top to bottom, this script basically does this:

  1. Setup Script
  2. Import libraries
  3. Create the NetMiko connection object with needed values
  4. Execute the connection with the object that was created and do this within the print function. Then return the output to the user.
  5. Disconnect the session

There is one thing I want to focus on that is a large part of NetMiko. Take a look at this line:


We already know what the connection object that “net_connect” is from the example before, but notice how “find_prompt()” is attached to it? This is a specific method that is available to the “net_connect” object. In this case, it pulls the current prompt from the network device you are working with as shown below in the case of my home environment:

Only thing left at this point is to branch out and see what other methods are available and begin to see what is possible!



Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.