(Hey! This article is almost 2 years old 🙂 Look here for something about the Clean Archictecture in 2021) An ideal project? If someone asked about the features of an ideal project, responses would surely mention a few specific things. First of all, an ideal project would have a clean codebase that is simple to […]
How to use code coverage in Python with pytest?
Basics What is code coverage? In the simplest words, code coverage is a measure of exhaustiveness of a test suite. 100% code coverage means that a system is fully tested. Why bother about code coverage in Python? Theoretically, the higher code coverage is, the fewer defects a system has. Of course, tests are not enough […]
How to implement and use Command Bus in Python with Injector?
What’s a command bus? Command Bus is an incarnation of Mediator design pattern. It provides a way to decouple the code structure that sends a command to its receiver. It becomes handy with CQRS implementation with regard to the write stack. Commands are implemented as immutable data structures. It can be done with e.g. dataclasses […]

Python & the Clean Architecture in 2021
It’s been almost 3 years since I used the Clean Architecture in production for the first time. I made it to quite a few conferences to talk about it (e.g. see Clean Architecture in Python talk from PyGotham 2018). Also, I wrote an article about the Clean Architecture that made it to RealPython.com newsletter. …but […]

Modular monolith in Python
Microservices are not the only way I remember when the microservices boom started. Truth to be told, it still echoes strongly to this day. You could see conferences agendas packed with talks about microservices, articles galore, finally books and frameworks. At some point, I was afraid to open my fridge. Everyone and their dog wanted […]

@staticmethod considered a code smell
Python offers quite a few built-in decorators that can be used to give methods of classes certain superpowers. @property turning method into a read-only field-like attribute is a classic example. Or @classmethod – a method that receives a class as a first argument, not an instance. Fun fact, this kind of method is usually called […]

How to implement a service layer in Django + Rest Framework
From this article you will learn: what is the service layer? the problem solved by a service layer how to refactor to services from ModelSerializers What is the service layer? A service layer is a set of classes or functions, called services, that together form an API for a single package or application. We can […]

Encapsulation is your friend, also in Python
What is encapsulation? Encapsulation is an act of deliberate limiting access to certain software components. The most common usage is to hide certain attributes of objects from other objects that use it. The most vivid example is the usage of so-called access modifiers, private and protected in languages that support it, for example, PHP: Running […]

How to patch in Python?
What is (monkey-)patching in Python? (monkey-) patching is a technique for changing code behaviour without altering its source. It is done in runtime, usually by overriding attributes of existing objects. An object can be an instance of some sort, a class or even a module. The technique is most commonly (ab)used for tests when we […]

Beware of chicken testing! (or mocks overuse)
Need for mocking Dealing with problematic dependencies is an indispensable part of software testing. Often, we cannot or do not want to rely on 3rd party service/network communication/hard drive etc., especially in unit-tests. The reasons vary; external dependencies are usually slow, fallible and difficult to put into the expected state before the actual test. Consider […]

Stop naming your python modules “utils”
Imagine the following situation: there is a software developer that is either adding new code or refactoring existing one by extracting a class/function. They have to place code somewhere, but it does not seem to fit anywhere. So what does a developer do? They create a new module – utils.py. Why utils is a terrible […]