Getting into Python: A Guide for Networkers Part 1

Getting into Python: A Guide for Networkers Part 1

No, you are not mistaken, it is 2017 and I'm writing this blog about networking types learning python.

I understand that this may all sound a little 2012 but I think I've actually got good reason to write and encourage other like-minded network engineers to get into learning python. But rather than just me pontificating like a roomful of tiresome podcasters I want to provide some specific examples of how and why. You know, useful stuff.

What's my story?

I've covered this in other areas of the blog so a potted history:

  • No CS background, no coding experience prior to 2014.
  • Learnt networking through a combo of NetOps, PoC hands-on and now general consultancy. Plus study, study and some more study.
  • Around 2012-2014 I hated all the marketing on steroids that was SDN. I simply could not relate that to my day to day work on network design and configuration. But the idea of learning to code did interest me.

How did I get into python?

During all the buzz around SDN there was a line of discussion about network engineers using python to configure networks, rather than the CLI of different OS. This more often than not came with the mandatory BS that all network engineers would be out of a job by about, erm, now if they weren't masters of software dev.
However, in an effort to learn something new I had a crack at codeacademy's python course and Zed Shaw's 'Learn Python the Hard Way'.

I found both of these very heavy going, constantly being told python is easy to learn, going over exercises about shopping lists and rubbish text role-playing games, I could not relate anything I was learning to my day job configuring networks. Consequently I restarted both courses at least twice and really didn't learn that much.

I found, like exercise, learning to code was very hard to get started with, difficult to keep up, and very easy to skip at the end of a working day.

What changed?

Approach

Early 2016 I told myself that this would be the year I make real progress, I ran through Jessica McKellar's python videos and Bill Lubanovic's 'Introducing Python', both for O'Reilly and both available on Safari.
The real difference was not so much the subject material, though good, but my approach, little and often, try to do some study each day no matter how small. Something I definitely did learn from Zed Shaw's writing was not to worry whether I got it or not, just keep typing out the examples, at some point in the future it will click.

The one thing you absolutely must not do is stop.

Keeping up momentum is key. Even if that is just 15 mins a day, I found I had to keep turning my brain back on to these weird concepts in order to make any progress.

Relevance

Then, just as I was starting to feel comfortable with the basics, I discovered Kirk Byer's netmiko project. Netmiko is written in python and makes it very easy to SSH into networking devices to issue commands and handle CLI outputs. This was the intersection that I needed to link my isolated book knowledge of python, and how to add 'apples' to the end of a shopping list, with my day to day networking. To make python relevant to my work.

Structured Data: The penny finally dropped

Using netmiko to SSH into devices and issue CLI commands was fun at first but I soon realized screen-scraping and parsing strings issued by the CLI was hardly a joy. When thinking 'There must be an easier way to do this' the penny finally dropped about the importance of the different data types, APIs and, in particular, why structured data, preferably json, is so important. Bear with me here, this post is about taking the first steps in python, I'll elaborate on these points in a later post.

Ok, so why learn python?

1. Network Automation & APIs

Things are slowly changing in the networking world but it is a tangible change. Whereas CLI and SNMP were our previous ways of interacting with devices, new methods of using the old interface, such as netmiko grabbing data via CLI, are gaining momentum.
But also new interfaces to devices are being built in the form of REST APIs on network kit. My employer has had switches on the market with said APIs right now. To interact with these new interfaces we can use, you guessed it, python. Interacting with networks using code via APIs means that stringing tasks together becomes that much easier. Am I discussing the hottest thing in networking right now, namely network automation? Yes, I am describing network automation.

2. Transferable skills

One thing that always encourages me when I find the going rough in my study is the thought that I'm not just learning python for networkers, some niche use case of the language. I'm learning a language that I can use for lots of different applications, including my infamous shopping list. There are REST APIs on all manner of things in our lives nowadays from TVs to websites to all those shiny new home automation products. Learning python allows you to interact with them and amaze your family and friends (if they are impressed by stuff like that).

3. Learning new stuff is fun

Though difficult at first once things started to come together for me I found at great sense of achievement in what I was learning. It has given me a much deeper understanding of IT in general, outside of networking TLVs.

4. Learning new stuff is essential

Finally, it is simply a case of don't get left behind. It is never a bad thing to learn new skills in this industry and just the new jargon that is becoming common parlance among those interested in network automation makes this all pretty opaque for those on the outside. If you don't know your class from your function, your dictionary from your list, now is the time to start.

Final Word

Please don't get me wrong, I'm not saying I'm sitting pretty as some well-versed pythonista. Far from it, I'm still just wrestling with the language. But I do think that I've now trekked through the murky swamps of the beginner stages and ready to push on up through the foothills to the next level. As such I've very glad that I stuck with it.
I also understand that anything I write is going to be pretty amateurish but I have those basic skills to hold a conversation about python and not be completely lost.
Moreover, I think it is my journey from networker with no code to networker with small amount of code that is of true benefit. Hopefully I can light the way and encourages others to tread this path.

Coming Up in Part 2: A practical guide on how to get started with python

NB: I do not monitor these pages for comments, if you want to get in touch: @joeneville_