During development, configuration files are often needed to easily change the behavior of the system. For example, the switch of Debug mode, database related settings, etc. are usually placed in configuration files.
In addition to the built-in module configparser provided by Python to easily implement configuration files, it can also easily implement configuration files using classes, such as the following two files are examples of configuration
DB_HOST = 'localhost'
DB_PORT = 8888
settings = Settings()
from settings import settings
However, nowadays development projects also often use
dotenv (e.g. python-dotenv) to make configuration easier.
In addition to developing the functionality of dotenv by yourself, you can actually choose to integrate class-style configuration files and dotenv easily with pydantic.
Jul 1, 2020
Useful Python Modules
, Python Programming - Advanced Level
‐ 5 min read