Configuration management in Python like a Boss(Pydantic with python-dotenv)

Anand Tripathi
Pythonistas
Published in
7 min readFeb 5, 2022

--

Note: For non-members, this article is also available at https://progressstory.com/tech/python/configuration-management-python-pydantic/

<a href=”https://www.freepik.com/vectors/cartoon">Cartoon vector created by vectorjuice — www.freepik.com</a>

The most basic thing of any application is the configuration variables. Some of them are constant throughout the application lifecycle and others keep on changing. The ones that are constants we just create a constant package and reference them from it. It helps us to avoid all the hardcoding in the application. And the other part that is most important is the variables that are kept on changing in the application that is generally known as Configurations.

So how to manage them, where to store them, how to access them? There are many questions related to configuration management. In this blog, we will be going to discuss the ways to manage configuration in Python. Especially the pydantic library

Overview

There are several ways of managing configurations. Let's talk about the most common ones

Constants

Store the configurations as a constant in the application and they will be applied once you start your application. This is the easiest way but the major disadvantage is that whenever you want to change the configuration you have to redeploy the…

--

--