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?
Articles on design patterns
Adventures in Import-land, Part II
By Ashlynn Antrobus on 8 April 2024
“KeyError: ‘GOOGLE_APPLICATION_CREDENTIALS‘” It was way too early in the morning for this error. See if you can spot the problem. I hadn’t had my coffee before trying to debug the code I’d written the night before, so it will probably take you less time than it did me. app.py: file_handling.py: See the problem? This was… Continue reading Adventures in Import-land, Part II
Elevate Your Python: Harnessing the Power of Abstract Base Classes (ABCs)
By Bob Belderbos on 26 January 2024
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)
Exploring the Role of Static Methods in Python: A Functional Perspective
By Bob Belderbos on 24 January 2024
Introduction Python’s versatility in supporting different programming paradigms, including procedural, object-oriented, and functional programming, opens up a rich landscape for software design and development. Among these paradigms, the use of static methods in Python, particularly in an object-oriented context, has been a topic of debate. This article delves into the role and implications of static… Continue reading Exploring the Role of Static Methods in Python: A Functional Perspective
How the Flocking Rules Can Help You Refactor Your Code
By PyBites Team on 10 August 2023
In this new podcast episode we are excited to have Chris May back to delve deeper into the intricacies of refactoring. Watch here: Listen here: We talk about the significance of the Flocking Rules, a set of guidelines derived from “99 Bottles of OOP” by Sandi Metz and Katrina Owen. These rules provide developers with… Continue reading How the Flocking Rules Can Help You Refactor Your Code
Django class based vs function based views
By PyBites Team on 28 February 2023
This post first appeared as an email on our friends list. We decided to publish it here because the question is still commonly asked 🤔 The other day I did a presentation on Django class based vs function based views. (Warning: this post is opinionated 😃) Also if you’re not into Django don’t stop reading just yet, because there are… Continue reading Django class based vs function based views
Reflections on the Zen of Python
By Bob Belderbos on 21 December 2022
An initial version of this article appeared as a Pybites email first. If you like it join our friends list to get our valuable Python, developer and mindset content first … How following the Zen of Python will make your code better, a lot better. This epic set of axioms (triggered by typing import this in the… Continue reading Reflections on the Zen of Python
Documentation-driven development with Sebastián Ramirez
By PyBites Team on 28 July 2022
Listen here: This week Bob and Pybites Coach, Robin Beer, interview Sebastián Ramirez, the creator of FastAPI, Typer and SQLModel. We talk about:– What he is currently working on.– How to balance the large amount of opportunities in his space (open source developer productivity tips).– The process of designing new libraries that are the glue between other ones.– The feeling of… Continue reading Documentation-driven development with Sebastián Ramirez
Refactoring Opportunities That Will Boost the Quality of Your Code
By Bob Belderbos on 19 April 2020
Refactoring is all about making your code more maintainable. In this article I will provide you with Python and generic software tips to write better code.
Learning Python Decorators by Example
By Bob Belderbos on 20 October 2017
Decorators are a sometimes overlooked feature and they might be hard to grasp for beginning Pythonistas. I agree with Aaron Maxwell that mastering them “can massively magnify the positive impact of the code you write”, so make sure you add them to your toolkit if not done so already. In this article I explain what they do, why you want to use them and give some practical examples.