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.

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.

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.

Create a Tkinter Gui With Sqlite Backend

By George El. • March 2020 • Reading time: 4 minutes

In this post I will show you how to create a single gui app using tkinter as frontend and sqlite as a backend. Python has many gui libraries and tkinter is one of them that is supported natively, that is you don’t need to install any extra modules. The app has the ability to search, add, update and delete router from a sqlite database.

How to Talk to Mysql Databases

By George El. • August 2019 • Reading time: 7 minutes

In this post I will describe how to use python to execute raw queries on mysql databases. install the database First we need to install mysql or maria-db (a fork of mysql) either in unix or windows. if you have windows 10 you can install mysql on wsl (windows subsystem for linux).