What is the Repository Pattern and How to Use it in Python?

The repository pattern is a design pattern that helps you separate business logic from data access code. It does so by providing a unified interface for interacting with different data sources, bringing the following advantages to your system: A practical example Let’s use Python and sqlmodel (PyPI) to demonstrate this pattern (code here): Note: In this implementation,… Continue reading What is the Repository Pattern and How to Use it in Python?

Leveraging typing.Protocol: Faster Error Detection And Beyond Inheritance

Introduction Two weeks ago I wrote an article about ABCs and interface enforcement. Shortly after I learned that you can do this as well with protocols. Python 3.8 introduced quite a groundbreaking feature that further advanced the language’s capabilities in type checking: the typing.Protocol which allows Python developers to define and enforce interface contracts in… Continue reading Leveraging typing.Protocol: Faster Error Detection And Beyond Inheritance

Elevate Your Python: Harnessing the Power of Abstract Base Classes (ABCs)

Introduction One cool object-oriented programming (OOP) technique / pattern is enforcing consistent interfaces. In Python you can use Abstract Base Classes (ABCs) for that. 🐍 Using ABCs ensures that all subclasses implement the required methods. This can make it easier to maintain and extend the existing code base. Update Feb 2024: you can also leverage… Continue reading Elevate Your Python: Harnessing the Power of Abstract Base Classes (ABCs)