Category Archives: Python

Web Apps with Python and Flask using Web Forms

We know that Python programming language can be used to create CLI applications. But, in most cases, CLI applications are used on your local PC.

There are examples when we want to present our calculations or some results in a form that might be suitable for the Internet. To achieve this we need to build a webpage.

In our scenario, we are presenting an example of using Flask and Python script that interacts with our written HTML code. As an option when we can take user data, entered from a webpage, we use WebForms.

There are a few things that you need to think about before you start building your first web app with Flask and Python. First is choosing a suitable Python IDE and build a virtual environment with Flask and Python. Next thing is to see how your Python script will route to the specific resulting  URL. And of course, using Jinja2 templating to use variables that interact with values between Python script and HTML code.

Bellow is our free code example for a basic Web app that calculates Summation or Product of a sequence.

Visualization of Network Device connections with Python

In many occasions during network design, network administration or troubleshooting of the network we are dealing with the issues: – How to visualize our network?. Reasons for this can be many, starting from different operating systems of devices, different vendors etc. And because of these and many other reasons that might be obstracles, we can’t represent our network topology using network software.

To avoid manual drawing of the network topology we are showing you example how to use power of Python coding to achieve this goal.

In this Lab example we are providing option to use Excel template file ( 1. Template of devices Next Hopes) where we may populate data needed to visualize our network. This file can be shared between the collegues in the enterprise or telco companies and data can be recorded.

Using those data we are able to implement intermediate Python coding to read those data from excel document, which is created in a format as template and if you follow instruction how to use this format it doesn’t matter how much network devices you enter or how many Next Hopes are per specific device. Code is designed to accept data and translate them in a form of dictionary.

Data in this dictionary data format later might be changed in other formats like List, or to represent their Key data separately and Value data separately as well. In our case we use {Key1:[Value11, Value12, …], Key2:[Value21, Value22, …], …} dictionary form.

What is next used, is Graph representation – connection between devices (called ‘edges’ in the Graph theory). Of course, network devices are ‘vertices’ (nodes or points) regarding Graph theory.

To be able to Visualize network connections between devices we use NetworkX Python package.

Lab code and details can be found in the following document: 1. Visualization of Network Device connections with Python.

How to use Bash Scripts and Python code to create a project?

We know that during writing Python code, sometimes because of lack of programming experience, or because of short deadline or because of the complexity of the output format of data from Python code we may use as support Bash Scripts to achieve our planned goal.

Depending of our needs in Bash Script we may execute one or more Python codes, or we can collect output from a Python file and we will process it and create the result we expect.

Bash Scripts can be useful especially in cases where we need to analyze some text saved in a document and sort data from it. So, during this process of creating your project, it is useful if you can create temporary text files and later in the Bash Script you will remove them. The intention is to store some changed data in the new file, and after the operation is done this file is no longer needed. In this case, you do not create new documents that will be junk files.

As an example we will present a simple project, that plots all (X, Y, Z) dots that solve the equation:

x2+y2=z2

To understand the solution for this equation, we know that integer and float numbers can be a solution to this equation, but also there are complex numbers that can satisfy this solution.

This example is shown in the following document x2+y2=z2