This eBook includes the following formats, accessible from your Account page after purchase:
EPUB
The open industry format known for its reflowable content and usability on supported mobile devices.
PDF
The popular standard, used most often with the free Acrobat® Reader® software.
This eBook requires no passwords or activation to read. We customize your eBook by discreetly watermarking it with your name, making it uniquely yours.
Also available in other formats.
Learn how to simplify Cisco network management with practical Python automation.
Modern networks demand speed, accuracy, and scalability. Hands-On Cisco Automation with Python teaches network professionals how to automate common Cisco IOS tasks using Python and three widely adopted tools: Netmiko, NAPALM, and Nornir.
This practical, example-driven guide shows how to replace repetitive manual work with reusable scripts that configure devices, collect operational data, and validate network state. Readers follow clear, step-by-step examples that explain both the Python code and the Cisco IOS commands involved.
The book focuses on real-world automation, not theory, making it ideal for readers new to network automation who want immediate, usable results.
What Youll Learn
Who This Book Is For
Introduction xxiii
Chapter 1 Introducing Netmiko, NAPALM, and Nornir 1
The 3 Ns: Netmiko, NAPALM, and Nornir 1
Automation and Programmability for All Levels 4
How Much Cisco IOS and Python Do I Need to Know? 4
What Do I Need to Get Started? 5
Using AI as an Alternative to Physical Equipment 6
Summary 7
Part 1 Netmiko
Chapter 2 Getting Started with Netmiko 9
Why Start with Netmiko? 9
A First Look at a Netmiko Program 10
The Basic Netmiko Framework 11
Optional: Exploring Python Classes, Objects, Instances, and Methods 15
Your Turn 17
Sending Command Output to a Variable 19
The send_command_expect() Method 23
The save_config() Method 26
Debugging Netmiko by Using the Session Log 28
Summary 34
Chapter 3 Configuring Devices with Netmiko 35
The send_command() Method 35
Summary 50
Chapter 4 Accessing Multiple Devices with Netmiko 53
Using a Variable to Store an IP Address 53
Understanding Python for Loops 54
Iterating Through Multiple Devices 56
Using Dictionaries to Store Device Connection Parameters 65
Using Pythons getpass() for Secure Password Input 71
Using Netmiko Exceptions for Troubleshooting 73
Maintaining Multiple SSH Connections Simultaneously 77
Summary 81
Part 2 NAPALM
Chapter 5 Introducing NAPALM and Structured Data 85
What Is NAPALM, and How Is It Different from Netmiko? 85
Installing the NAPALM Library 88
Basic NAPALM Framework 88
How NAPALM Retrieves Data Without an API on Cisco IOS 91
Good News, Bad News: Understanding Structured Data 92
get_facts(): Our First NAPALM Method and Dictionary 95
Assigning the Dictionary to a Variable 97
Understanding Different Types of Values in a Dictionary 99
Creating a NAPALM Dictionary Without a Device 100
NAPALM Methods 102
Using Python Interactive Mode to Experiment with NAPALM 105
Summary 107
Chapter 6 Understanding Python Dictionaries with NAPALM 109
How NAPALM Organizes Data 110
A Single Dictionary 110
A Dictionary of Dictionaries 115
A List of Dictionaries 122
Sample Program Using All Three Types of Dictionaries 127
Comparing the Three Types of Dictionaries 131
Methods by Type of Data Structure 133
Summary 135
Chapter 7 Iterating Through NAPALM Dictionaries 137
Live or Simulated Data 138
Working with .keys(), .values(), and .items() in NAPALM Dictionaries 140
Using a for Loop with Dictionary Methods 143
Determining the Type of Value 147
Looping Through Key/Value Pairs with .items() and Processing Values with isinstance() 153
Iterating Through a Dictionary of Dictionaries 167
Iterating Through a List of Dictionaries 173
Summary 176
Chapter 8 Configuring Devices with NAPALM 179
A Quick Overview of NAPALM Configuration Methods 179
Introducing Our Example Scenario 180
Configuring a Device with load_merge_candidate() 182
Using the cli() method 188
Using load_replace_candidate() to Replace the Configuration 193
Displaying Running and Startup Configuration Files 199
Next Step: Nornir 200
Summary 201
Part 3 Nornir
Chapter 9 Introducing Nornir: A Pythonic Framework for Network Orchestration 203
What Is Orchestration? 204
How Does Nornir Compare to Netmiko and NAPALM? 205
How Nornir Uses Netmiko and NAPALM 206
Installing Nornir 207
Basic Nornir Framework: Python and YAML 207
Your First Nornir Program and YAML Files 208
Whats Next? 218
Summary 219
Chapter 10 Using Nornir with Netmiko 221
Installing Support for Netmiko: nornir_netmiko 221
Using Nornir and netmiko_send_command() 222
Sending Configuration Commands with netmiko_send_config 236
Summary 246
Chapter 11 Using Nornir with NAPALM 247
A Quick Review 247
Installing Support for NAPALM: nornir_napalm 249
nornir_napalm Tasks 250
Advantages of Using These Tasks with Nornir 251
Using Nornir and the napalm_cli Task 251
Using Nornir and the napalm_get Task 261
Using Nornir and the napalm_configure Task 268
Summary 276
Chapter 12 Inventory Management with Nornir 277
A Quick Overview with a Focus on Inventory 278
Where Inventory Data Comes From 280
A Note on Filtering 281
Inventory Management Core Architecture 282
Hosts 282
Groups 289
Effective Values After Inheritance 292
Using Group Data for Filtering 295
Defaults 296
Accessing Inventory Data 298
Inventory Plugins 300
Inventory Plugin Options 301
Summary 319
Part 4 Whats Next
Chapter 13 Whats Next 321
Why Network Automation Became Necessary 321
Netmiko, NAPALM, and Nornir in Context 324
Ansible, NETCONF, and RESTCONF: Expanding the Automation Comparisons 331
Understanding YANG Models 332
Understanding APIs 334
Artificial Intelligence and Network Automation 336
Closing Thoughts 338
Appendix A Python Virtual Environments 341
Appendix B Understanding expect_string with send_command() 345
Appendix C Using Python Dictionaries as NAPALM Outputs 347
Appendix D The Relationship Between Python Dictionaries and JSON 353
Appendix E Understanding Objects and Variables in Python 355
Appendix F Using a Recursive Function to Handle Nested Dictionaries of Any Depth 357
Appendix G Using Tabular Output 359
Appendix H Using Public and Private Keys 361
Appendix I Netmiko-Supported Network Operating Systems 365
9780135463192, TOC, 3/25/2026
