Member-only story
My favorite way to configure a Python project
Pydantic-settings at our rescue
The first thing I want to note is that the following recommendations are valid for web applications or API services. For other types of applications like Command Line Interfaces, they might not be the best suit, even if I think they are also relevant.
Also, what I mean by configuration are things that can be changed between deploys or environments like:
- database server URLs
- secret key used to sign cookies
- credentials to connect to an external service
- etc…
I don’t include internal application configurations like route URLs that should be handled directly in code.
The are various ways to configure your application. We will see the most common and the one I use and how I use it.
Configuration with files
A common approach I see in various projects is to use files to configure the application. In Python, many formats are supported directly via the standard library or through third packages. The common ones are:
- Ini file: This format is well-known in part because it is often used to configure Python packages.
- Toml: This format is also used to…