Ashraf Miah
Nov 18, 2022

--

Whilst the use of Pydantic has other uses, it's a bit over the top in trying to avoid the use of the `os` module.

The `python-dotenv` module you cited before itself has a `dotenv_values` function that can bypass the environment entirely and load the values into a variable. It's possible to overlay multiple files representing differing levels of inputs or secrets. In effect having a "local" file override a "global" file.

In either case, the key advantage in avoiding the `os` module is really that you get the inputs from a `.env` file instead which can be set to be ignored in a VCS for example and is portable.

--

--

Ashraf Miah

CTO, Data Scientist & Chartered Engineer (MEng CEng EUR ING MRAeS) with over 20 years experience in the Aerospace, Rail & Energy Industry.