Building a Python Application Docker Image with Multi-Stage Builds

This article describes how to build a Python application Docker image, optimized for production use, using multi-stage builds.

The idea is to use a separate build stage to build the dependencies (where the build process itself may require other dependencies, like build tools, compilers, header files, etc.), then copy the …

more ...

Django Migrations on Kubernetes

Concurrent setups are helpful for scalability and performance, but may bring complexities for consistency. Not all tasks benefit from concurrency though. For example running database migrations is a task where consistency and controlled execution is more important than concurrent execution, if that's desired at all.

In a distributed setup, how …

more ...

Python Context Managers

Date Tags python

Sometimes it's helpful to wrap some code in a given context. Either the code requires some resource from the context, or the context adds some aspect to the code.

Python provides with statement to create a context for the followed block of code.

with context_manager:
    # this block runs within the …
more ...

Python Methods As Decorators

Python function decorators (PEP 318) make it easy to modify behavior of functions (or add new functionality), without changing them. We won't introduce them here as they're documented extensively.

We're demonstrating a specific case, where we have a class and we want to to use one of the methods of …

more ...

Skipping Tests

Sometimes a test should be skipped for a good reason (some resource is not available for a while and mocking is not an option, or tests are assumed to be impacting each other, etc.).

Most test runners support a way to mark a test to be skipped in a proper …

more ...

Python Virtual Environments

Date Tags python

Problem: Different applications might require different versions of the same libraries, which version of those libraries should be installed?

Problem: There are tools installed with the operation system written in Python, they require specific versions of some libraries, and the ones provided by the operating system packages are to satisfy …

more ...