This post is part of an ongoing series - see all the posts below.
I created this series to help Network Engineers get started with Python without feeling overwhelmed. Everything here is explained from a networking perspective, using examples you'll recognize from your everyday work. We'll start from the very beginning and build up one step at a time, so by the end, you'll have the skills and confidence to start automating your own network.
As always, I aim to keep things simple and approachable. Each section builds on the previous one, so I recommend following along in order. You do not need to be an expert programmer; in fact, you do not need any prior programming experience at all. As long as you are comfortable with networking concepts and have access to a computer, you are ready to get started.
But Can AI Not Just Teach Me Python?
Fair question, and one I have thought about a lot while writing this series. AI tools are genuinely great at writing code these days. You can ask one to build you a script that connects to a device and pulls the running config, and it will spit out something workable in seconds.
So why bother learning Python at all?
The short answer is, if you cannot read Python, you cannot check what the AI gave you. You cannot fix it when it breaks. You cannot tell whether the "workable" script is actually doing the right thing, missing an important step, or leaving a security hole. You are essentially trusting a stranger with your network, and hoping for the best.
The engineers who get the most out of AI tools are the ones who already understand the language. They can read the output, spot mistakes, adapt it to their environment, and push back when the AI is confidently wrong (which it will be, often). Without that foundation, AI feels magical for a while, and then bites you the first time something goes sideways.
This series is not trying to compete with AI. It is trying to give you the base you need to work with it well. Read this cover to cover, work through the examples, and by the end you will be able to look at any Python script (whether you wrote it, someone on your team wrote it, or an AI wrote it) and understand what it is doing.
Use AI. Use it a lot. But do the reading too. The combination is where the real value is.
Introduction
If you are a network engineer, you have almost certainly heard by now that you should be learning Python. Maybe you have tried a course, watched a few videos, or read a chapter of a book and quietly given up because none of it felt relevant to what you actually do at work.
You do not need to be an expert (I am not one either), but you should reach a point where you can comfortably read and understand other people's code, make changes, and write moderate Python scripts yourself. In the age of AI, there is no excuse to avoid learning Python or any other language, for that matter. It will save you time, make your work easier, and open up possibilities you did not have before.
Python is a programming language (duh) that is simple to learn and widely used across many fields, including networking. For network engineers, Python is especially powerful because it allows you to automate repetitive tasks, connect to devices, collect data, and even build custom tools. Instead of logging into devices one by one to run commands, you can use Python to handle dozens or even hundreds of devices consistently and reliably.
This series is written for network engineers who may not have any programming background but want to get started with Python for practical day-to-day automation. The only prerequisites are basic networking knowledge and access to a computer.
Python Installation
The only requirement to start learning Python is to have it installed. If you use Linux or macOS, you likely already have Python 3 pre-installed. Here, I specifically mention Python 3 because Python 2 is an older version that is no longer supported, while Python 3 is the modern standard with improved features and ongoing updates. To check if you have Python 3 installed, run python --version or python -V.
python --version
Python 3.10.12
python -V
Python 3.10.12
If you see something like Python 2.x, try python3 --version. The reason you might get Python 2.x with the python command and Python 3.x with python3 is that some systems still keep Python 2 as the default for compatibility, so python3 explicitly calls the newer version.
If the output shows at least Python 3.10, you are good to go. Ideally, you want Python 3.12, but do not worry too much about it for now.
If you do not see Python 3 installed, there are plenty of guides and videos online that walk you through the process for your operating system. If you still have trouble installing, reach out to me, and I will try to help. Just make sure you have Python 3.10+ before moving forward.
- On Ubuntu 22.04 or later, Python 3.x comes pre-installed out of the box, so you are ready to go.
- If you are using macOS and do not have Python3 installed, you can use Homebrew, the package manager for macOS. First, install Homebrew (you can find instructions on their website), and then run
brew install python3to install Python 3. - If you are using Windows 10 or 11, you can make use of Windows Subsystem for Linux (WSL) to install and use Python. This is often an easier and cleaner way compared to installing Python directly on Windows, since WSL gives you a Linux environment inside your Windows machine. To get started, visit the Microsoft Store, download and install Ubuntu WSL, and then launch it as you would any other application. Inside WSL, if you run
python3 --version, you will see Python already installed, so you can proceed without extra setup.
A Quick Look at How Python Works
Before we dive into writing code, it is worth spending a minute on what Python actually is and how it runs your programs. You do not need a deep understanding to be productive, but a bit of background will help the next few sections make more sense.
Python is an interpreted language. That means when you write Python code, you do not have to compile it into a separate executable file before running it, like you would with languages like C or Go. Instead, there is a program called the Python interpreter that reads your code and runs it directly, line by line. That is the thing you just installed when you set up Python on your machine.
Behind the scenes, the interpreter does convert your code into something called bytecode before executing it, but this happens automatically and you do not need to think about it. You write plain text files ending in .py, and the Python interpreter runs them.
One last thing worth mentioning, when people say "Python", they almost always mean CPython, which is the standard implementation of the language and what you have installed. There are other implementations like PyPy and Jython, but you can safely ignore those for now. Everything in this series runs on CPython.
With that out of the way, let's look at the two main ways you can actually run Python code.
Python Interpreter vs Running a Script File
When learning Python, you might see some tutorials showing code being typed directly into something called the Python Interpreter. The interpreter is an interactive mode where you type Python commands and see the results immediately. It is useful for testing small snippets of code or experimenting with ideas quickly.
❯ python3
Python 3.10.12 (main, Jun 21 2024, 21:09:27) [Clang 15.0.0] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> print('Hello')
Hello
>>> quit()
Here we are using the Python interpreter to print the text Hello on the screen. The interpreter lets us type Python commands one by one and see the results instantly. After running the command, we used quit() to exit the interpreter and return to the terminal. This is a quick way to test simple code without creating a file.
On the other hand, you can also write your code in a .py file and run it as a script. This approach is better for anything more than a few lines because you can save, edit, and reuse the file. Running a file also makes it easier to share your code or keep it organized for larger projects.
Here, we have a Python file called main.py with the same print('Hello') statement. Instead of typing it directly into the interpreter, we save it in a file and run it using the command python3 main.py.

The output is the same, but this method allows us to keep the code for later use, make changes easily, and work on larger projects without retyping everything.
In this series, we will mostly use Python files since they are more practical for learning and working on real tasks. However, you should still be aware of the interpreter, as it can be handy for quick testing.
Visual Studio Code
In the previous screenshot, I am using an IDE called Visual Studio Code. An IDE (Integrated Development Environment) is a tool that makes writing code easier by providing features like code completion, syntax highlighting, and showing errors if you make a mistake. It can also help with running your code, managing files, and integrating version control.
You do not have to use VS Code. There are other popular options like PyCharm or even simpler editors if you prefer. Use whatever you are most comfortable with. With any IDE, the usual workflow is to create a project directory, open that directory in the IDE, and then create or edit your Python files inside it before running them.
VS Code also has an integrated terminal, so you can run commands or scripts without leaving the editor. To access it, go to Terminal > New Terminal. This convenience means you do not have to switch back and forth between VS Code and your system's terminal.
Your First Python Script
Once you have Python and an IDE installed, you can create a project directory (aka a folder), add a new file with a .py extension, and write something like print('Hello') inside it.
print("Hello")
Save the file as main.py, open a terminal in the same directory, and run it.
❯ python3 main.py
Hello
That is it. You just wrote and ran your first Python script. As long as you can do this and see the output, you are ready to start learning. Everything else in this series builds on top of this same simple workflow, write code in a file, save it, run it from your terminal.
A Preview of What is Coming
Before we move on, I want to show you a quick preview of what a real (very simple) Python network automation script looks like. Do not try to understand it, do not try to run it, just take a quick look. By the end of this series, every single line of this script will make complete sense to you.
from netmiko import ConnectHandler
cisco_01 = {
"device_type": "cisco_ios",
"host": "192.168.202.101",
"username": "admin",
"password": "admin"
}
connection = ConnectHandler(**cisco_01)
output = connection.send_command("show ip interface brief")
print(output)
connection.disconnect()
This script connects to a Cisco device over SSH, runs show ip interface brief, prints the output, and then disconnects. Right now, most of this probably looks like alphabet soup, and that is completely fine. We will start with the basics in the next chapter (variables, data types, and so on) and build up from there. By the time we come back to a script like this, you will understand exactly what every piece does and why it is written that way.
Why Learn Python as a Network Engineer
Before we move on, I want to take a step back and talk about why learning Python is worth your time as a network engineer. If you are reading this post, you probably already have some idea, but it is worth being clear about what you actually get out of it.
The biggest reason is time. Most network engineers spend a huge chunk of their day doing repetitive tasks, logging into devices, running the same show commands, copying output into a spreadsheet, making the same config changes across dozens of devices. All of this is exactly the kind of work computers are good at. Python lets you hand that work off to a script and focus on the actual problem-solving instead.
The second reason is consistency. When you do something manually across 50 devices, you will make mistakes. You will fat-finger a command, forget a device, or skip a step. A script does the same thing the same way every single time.
The third reason is scale. Doing something on one device is easy. Doing it on a thousand is impossible (unless you are crazy) by hand. Python does not care whether you have 1 device or 10,000, the script runs the same way.
And finally, it is just a useful skill to have. The industry is moving towards automation whether we like it or not. Knowing Python opens up better job opportunities, lets you contribute to projects you would not otherwise be able to, and makes you a more valuable engineer overall.
Some Practical Use Cases
To make this less abstract, here are some real things you can do with Python once you have the basics down.
- Bulk configuration changes - Push the same VLAN, ACL, or routing change to hundreds of devices in minutes instead of hours.
- Configuration backups - Connect to every device on your network, pull the running config, and save it to a file with a timestamp. Run it daily as a cron job.
- Compliance checks - Loop through your devices and check that certain configuration lines exist (like NTP servers, SNMP communities, or logging destinations, etc)
- Audit reports - Pull data from devices (interface status, software version, uptime, serial numbers) and generate a clean report or spreadsheet.
- Pre and post-change validation - Run a script before a change to capture the state of the network, run it again after, and compare the two.
- Interacting with APIs - Almost every modern networking platform (DNA Center, Meraki, Panorama, NetBox, and so on) has an API. Python is by far the easiest way to work with these APIs.
- Custom tooling - Build small utilities for your team, a script that generates configs from a template, a tool that checks if a list of IPs is reachable, a quick parser that turns messy command output into a clean table.
You do not need to be able to do all of this on day one. The point is that once you have the basics down, the door is open. Each chapter in this series gets you a little closer to being able to write scripts like this on your own.
