Leverage the charged energy of the Python Neighborhood
Like many coders, engineers, and folks who ‘program code tinker’ of the early morning in the tiny hours, I am considering new methods to improve my program code always. This is for most reasons. For instance, Comprehensions in Python can offer us with a brief and sweet solution to construct brand new sequences. They’re a concise and speedy solution to create new lists.
Python built-in features can help you save time
Python has many excellent built-in functions. Often, I’ve spent ages attempting to write the best program code I can and then discover one of the numerous underlying libraries could have saved me hrs (or even days!). Have a look at these Python library functions to check on in case you are replicating these built-in functions inside your program code. These are guidelines you might acquire overtime or insurance firms someone review your program code and deliver you a pull demand.
Recently, We was asked to provide a workshop on system automation. I had introduced on this subject 2 yrs ago, but 2 yrs can be a life time in the code planet. I had a need to repair this up, as there were some noticeable adjustments to the API. The chance was taken by me to update the code end-to-end. Now it may seem I live dangerously (when i perform all my demo’s live!). And I understand that performance issues, as does output. THEREFORE I used two Python libraries to provide me personally the output and efficiency quality I needed – Rich and scrapli.
Scrapli is fast…real quick
Final year, among our DevNet community people, tweeted about Scrapli. Scrapli may be the brain kid of extremely genius Carl Montanari. The real name scrapli — is “ just;scrape cli” (since in display screen scrape) squished jointly! scrapli’s objective is to be because and flexible as you possibly can while providing a thouroughly tested fast, well-typed, well-documented, basic API that facilitates both asynchronous and synchronous utilization. It was distributed by me a try also it was super awesome and fast too.
https://github.com/carlmontanari/scrapli
But there’s more, automagically Scrapli uses ssh, nevertheless, you may use netconf over ssh right now!
“scrapli_netconf is really a netconf driver built together with scrapli. The objective of scrapli_netconf fast would be to provide a, flexible, tested thoroughly, well typed, properly documented, easy API that facilitates both synchronous and asynchronous use. Working with each other scrapli and scrapli_netconf try to give a consistent (as is sensible) appear and feel when automating gadgets over telnet, SSH, or netconf (over SSH)”
https://github.com/scrapli/scrapli_netconf
Wealthy API makes your code shine
Therefore our code is currently faster because of Scrapli. Can we pretty ensure it is look more? The answer compared to that yes is, with Rich. Rich (that is compiled by full-stack software programmer, and Python specialist Will McGugan) is really a Python library for rich textual content and stunning formatting in the terminal. The Rich API makes it simple to include color and design to terminal output. Rich can render fairly tables also, progress pubs, markdown, syntax highlighted supply code, tracebacks, and much more – from the box.
We tried this with pprint module and json. When obtaining a lot of json result from the always-on sd-wan sandbox back, utilizing the sd-wan sdk, adding Rich helps really, as code can pop, during demos, that is great as details show out clearly really.
I execute a lot of work/result with tables and Wealthy may render flexible tables with unicode container characters, plus there exists a large selection of formatting choices for borders, styles, cellular alignment etc
https://github.com/willmcgugan/rich
Your turn
So you know of the two awesome Python libraries now, let’s see everything you can build using them. If you are done constructing your code you will want to share it on DevNet Code Swap. If you are searching for a few more inspiration have a look at this code scrapli_netconf_BGP.
If you possess any feedback i want to know in the remarks section below – leave me a note, ask me another question, anything you want.
- Follow @bigevilbeard
- Follow @CiscoDevNet
Related resources
- Visit the DevNet Networking Dev Center to get and find out about your network automation make use of case
- Learn about Cisco DevNet professional certifications