How to Squash and Merge Django Migrations

Django Migrations are one of the main features that keep me coming back to Django for most of the projects I work on. Being able to simply define the database model in python, and then sync it with the database schema using migrations adds so much value to a project.

Unlike frameworks such as PHP’s Laravel where you have to define your own migrations, Django will automatically create a migration file as soon as we change our model. It’s... Read more

Deep Dive Guide Into Python Type Hints and Type Checks

In 2012 a Finnish Ph.D. student from Cambridge named Jukka Lehtosalo approached the author of Python Guido van Rossum at a PyCon event regarding a new programming language named Alore that he had created which was heavily inspired by Python, but with the addition that it also supported optional type annotations.

Alore allowed you to write code with types, and then it used a transpiler to turn the code into pure Python. This pattern is popular and we can... Read more

How to Render Markdown Syntax as HTML Using Python

Storing user-created articles in your database as Markdown Syntax instead of the final rendered HTML solves so many problems. It’s not only more secure and helps you prevent XSS injections into your content, but it also makes it much more flexible to change the rendered version of the content at a later stage in the lifetime of your application.

This article that you’re reading right now has been written using Markdown Syntax. That’s how it’s being stored in the database,... Read more

Write Unit Tests with Python's unittest Module

Writing great unit tests is one of the things that I’ve discovered throughout my career to have the single most impact on the quality of code that I produce as a software engineer.

Obviously, there are other things such as doing code reviews or working in great companies with talented coworkers, that has also inspired me to grow as a programmer, have more pride in the work I do, and to produce more stable and beautiful code. But none of... Read more

Learn Basics of Logging in Python

The Python logging module is in the core of things that you need to learn to master the Python programming language. By using logging extensively throughout your program, you will not only massively improve your ability to debug reported errors, but you’ll also get great insights into how your users are interacting with your application.

Unfortunately, even though logging should be part of any program, it is often overlooked by lazy, and naive programmers who focus more on the quantity... Read more

How to do Zero Downtime Deployments of Docker Containers

Green and Blue Deployments, or Zero Downtime Deployments is a hot topic that is relevant for any DevOps Engineer. It’s the discussion of how we can update our application without causing any disturbance to the user experience while we’re doing it.

I love using Docker and it has been one of the most amazing tools that I’ve adapted to my workflow within the last few years. In almost all of my projects I use Docker Compose to define my containers,... Read more

Use Gunicorn To Serve Your Django or Flask WSGI App

Using Gunicorn to serve your python WSGI web application is the next step to take after you’ve finally spent those days creating the first prototype of your new application and you’re ready to serve it in production.

But what is WSGI? What is Gunicorn used for and why do you need to combine Gunicorn with something like Nginx? Isn’t Gunicorn a web server by itself?

In this article, I’ll take you through how we can use Gunicorn to serve our... Read more

How to Store Terraform State on S3 and Cloud

Terraform is an amazing tool that allows you to keep track on the state of the infrastructure that is running at your Cloud Provider, and it uses this state to understand if it needs to update, tear down or provision new instances of the different pieces of your infrastructure.

So for example, the first time you run Terraform your state is empty. You don’t have anything running at all. This means that Terraform will try to create everything that you... Read more

How to Split and Organize Terraform Code Into Modules

Terraform is one of my favorite tools that I picked up last year and part of why I like it is the ability to organize your infrastructure as code into readable, logical chunks of digestible code that any developer can lookup and easily understand within a quick glance.

Before I started using IaC (Infrastructure as Code) tools such as Terraform I was defining all of my infrastructures within the dashboard of the cloud provider that I was using for the... Read more

How to Run Command in Background or Daemon with Linux

What if you have a task that you want to be running at all times on your system, but you don’t want to run it in a terminal manually, instead you want it to always be running in the background of your Linux environment. How would you achieve this?

This is a very common task that you might run into fairly quickly in the world of DevOps. For example, imagine that you need to monitor your database to make sure... Read more