Sending Messages from Web Server to Web Client using Websockets, Redis and Webdis

Sometimes your web application will initiate some server-side code that runs for an extended period. This can be a problem for a user left staring at a web page with no feedback – the temptation is to re-submit, go back or even close the application. I found this to be particularly relevant while working on network automation applications that involve a lot of relatively slow interactions with network devices.
What is needed is a way to continuously update the user with messages so that they can see that the application is functioning correctly.
This post will describe how to use WebSockets, Redis, and Webdis to send messages from the server-side of your web application to the client.

The web client “subscribes” to the message queue and the server “publishes” to the queue. Every message published by the server is seen by the client. The client does not have to request the message.
Continue reading Sending Messages from Web Server to Web Client using Websockets, Redis and Webdis

How do Python imports and __init__.py files work in a package

Python packages typically utilize mechanisms like imports, __init__.py files, and inheritance to create scaleable, and reusable code. In this post, we will look at how these mechanisms work by exploring a piece of code that uses the Netmiko library.

Continue reading How do Python imports and __init__.py files work in a package

Using Parameter Substitution for Column Names with Python MySQL Connector

The use of data parameter substitution with MySQL Connector is well documented:

To create a new row in a table by passing in multiple data parameters the syntax might be:

cur.execute('INSERT INTO table1 (name, address, phone, postcode) values (%s, %s, %s, %s)', ('John', '1 Front Street', '416-111-1234', 'N4R2E5'))
db.commit()

Where the %s are placeholders for the data values being passed in the following list.

Continue reading Using Parameter Substitution for Column Names with Python MySQL Connector

Learning Python 5 – Practical Projects

As with learning anything, practice is the key and with Python that means typing code into the CLI – you will not make much progress just reading blogs or watching tutorials. In an effort to learn quickly it can sometimes be tempting to think, “I will watch the next video, then I will try a practical exercise”. It’s not until you try and code something that you realize you have not taken it in as well as you thought.

Continue reading Learning Python 5 – Practical Projects

Learning Python 3 – Tutorials

There are so many Python tutorials available online that sometimes it is difficult to know which one to use. The quality can vary significantly and sometimes the author may be too fast or too slow or just have a style that does not work for you. The following authors are my favorites based on their speed of delivery, style of delivery, use of examples, and overall consistent quality.

Continue reading Learning Python 3 – Tutorials

Learning Python 2 – Online Training

Which online training sites have good content?

Paid online training can provide a more structured approach to learning. I have found it most useful to start with some paid online training courses and then supplement or fill in the blanks with free online tutorials. I have found the following sites useful:

Continue reading Learning Python 2 – Online Training