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.

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.

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.


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.

Abstract Classes in Python

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

In my post Classes in Python I have an example of creating a class named Car and instantiating this class. In reality you would rarely do something like this, but rather use this class as a base class in order to create subclasses. Subclasses are classes that extend the base class and inherit all functionality from it.

Sort Html Links in One Line

By George El. • May 2019 • Reading time: 2 minutes

Recently I had to sort a lot of html links in a program I created, so I decided to write a simple one line script to do it in python. The html links are in file called links.txt The file looks like this: <a href="file1">a</a> <a href="file2">c</a> <a href="file3">z</a> <a href="file4">b</a> <a href="file5">x</a> <a href="file6">e</a> <a href="file7">f</a> <a href="file8">g</a> <a href="file9">y</a> the code I came up with is:

Null Object Pattern

By George El. • April 2019 • Reading time: 2 minutes

In this post I will explain a pattern used in OOP, called Null Object Pattern. This pattern allows us to use our code as usual even if what we get back is a null object. Lets first see an example without using the pattern. I will create a dictionary called Persons that will hold Person objects.