Python for Network Engineers

Should I Use Flask or Django for Web App Development?

By George El. • February 2021 • Reading time: 5 minutes

At some point you will want to write a web application. In python the two most popular web frameworks are Flask and Django. In this post I detail the pros and cons of each and which one should you use. I have used both so I have a pretty good picture of both.

10 More Git Commands Everyone Should Know

By George El. • February 2021 • Reading time: 3 minutes

Amend your last commit git commit -m "first commit" git add my_file1 git commit --amend You end up with a single commit. You must not have pushed the brach somewhere Discard changes in working directory The recommended command is “git restore”. The old command is “git checkout” Discard changes of a file in working directory

Regular Expression Functions in python with examples

By George El. • February 2021 • Reading time: 5 minutes

In this post I will explain all the functions in the re module and then go on to discuss capturing and non capturing groups, non greedy operator, look ahead and look behind positive and negative assertions. Regular expressions can be a little initimidating in the beginning, but once you learn how to use them, you can use them in every language.

Why Is Python Slow?

By George El. • January 2021 • Reading time: 2 minutes

This post is largely based on this video which I highly highly recommend from Pycon 2020. If you don’t want to watch the whole video, here is the most important points. Python is hundred times slower than compiled languages like C and GO and this is expected, since python is interpreted.

Nornir, Napalm, Ansible, Netmiko or Plain Python?

By George El. • January 2021 • Reading time: 4 minutes

What library do you need to use? There are a handful of libraries out there that do network related stuff. Lets review them. Ansible maybe is the most famous one. Ansible started as an automated framework for configuring servers, like installing and configuring web servers, databases etc. The network modules were added later.

Implement a Url Shortener Service in Flask

By George El. • January 2021 • Reading time: 5 minutes

In this post I will describe how to implement a url shortener service using flask. There are two main ways to implement a url shortener service. The first one is to take the URL and apply the md5 hash algorigthm. Then convert this 128bit number to base62 or base64. The problem with this approach is that the base62 results in a 21 byte string which is long.

Log to Console, File and SMTP With Logging Module

By George El. • December 2020 • Reading time: 2 minutes

In this post I will show you how to use the logging module to log messages to console, file as well as send email using smtp, depending on the level of the message Create a logger First we will create a logger and set level to DEBUG import logging logger = logging.

Build a REST API With FAST API

By George El. • December 2020 • Reading time: 3 minutes

In this post I will show you how to build quickly a REST API using the package FAST API The endpoints for each will be as shown First create a virtual environment and install fast api and uvicorn python3 -m venv env source env/bin/activate pip install fastapi, uvicorn Instead of putting all the endpoints in one file we will use a modular approach and use one file for the routers and one for the switches.

Flask, uwsgi, Nginx with Docker

By George El. • November 2020 • Reading time: 8 minutes

In this post I will describe briefly what is docker and how to run a simple python program in a docker container. Then I will do the same for a flask app using uswgi and nginx in different containers and then I will combine the two using docker-compose. What is a Container?

Threads vs Processes vs Asyncio

By George El. • November 2020 • Reading time: 6 minutes

In this post I will explain the difference between threads, processes and asyncio and what is the best approach to use when you want to configure your devices. Concurrency vs Parallelism Lets first explain the difference between concurrency and parallelism. Concurrency means that an application gives the impression that executes many tasks at the same time, but in reality only one task is executed at a time.