My programming language of choice: Python

With this post, I’ll like to share with you my thoughts, why programming may be relevant for network engineers and why I named it as the first learning area for network programmability and automation in my “how to start” post. Furthermore, I will explain, why I think python is the right choice to get started with programming, especially if you have never learned a programming language in your life before.

But why should you learn programming? The answer is for me quite easy, a good script can save you a lot of time and make you more effective in multiple ways. For my “Network Engineering life”, scripting helps me in the following topics:

  • Configuration generation
  • Processing information from the network (at scale)
  • Interacting with the network

The first language, not the last

Okay, first have a look at programming languages at all. There are many out there and I worked with some of them in the past. At the end, the programming language is just a tool and if you get started, I don’t think that you will just learn one language and work with that almost forever. You can start, in fact, with any programming language. For the scope of network programmability and automation, python is the right choice for me. It is quite popular, has a large ecosystem, is easy to learn and has a very good documentation from my point of view. With just a few clicks, you find a lot of (free) introduction courses and information on how to get started with programming at all based on python, e.g. at codeacademy or at "learn python the hard way".

Which version should I use? Python 2.x or 3.x?

I assume that you are new in this topic, and you might have heard, that vendors start to adopt python as a language for there APIs and also on there devices (for example on the Cisco Nexus 7000). You might also know, that these libraries are mainly based on python 2.x at time of this writing. But what does it mean?

To clarify this, we need to have a look back in the history. The python programming language is maintained in two trains, version 2.x and version 3.x which was released at the end of 2008. It removes and replaces some older code from Version 2 of the language, which leads to some incompatibilities between the versions (e.g. in exception handling, they are terrible different). This was one pitfall that I hit many time during my learning, when I researched a problem.

My recommendation is, that you start with python 3. You need to install it (version 2 is bundled with the most Linux distributions), but this will be the future of python and If you need to use the older version at some point, you can always fallback and focus on the differences between the two languages. My experience so far is, that you will always find code, which is compatible with python 2 and 3.

Python – from smaller scripts to larger applications

One additional benefit, which I discovered for me is the fact, that python is used in many areas, not just in scripting and programming smaller applications. It also scales to larger applications and the ecosystem provides many libraries for these deployments, e.g. in the area of User Interface programming and server side web development (using frameworks like Django, Flask etc.). Furthermore, there are many libraries out there for almost every topics, which I required so far (paramiko for SSH or ciscoconfparse to work with configuration files to name just some of them. Last but not least, the automation framework Ansible is also based entirely on python.

Conclusion

Which language you use is at the end up to you, but I think python is a good starting point. You can also start with Perl or any other language, but I think, python fits better in the topics of network programmability and automation from an ecosystem perspective. I also started after some time to work with python for web development. This has some benefit, when you combine the topic of network programmability with larger programming projects, you have just one language and don’t need to think about how they are able to interact.


Henry Ölsner avatar
About Henry Ölsner
Just another Network Engineer and hobby programmer