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.

Data Scientist and Chartered Aeronautical Engineer (MEng CEng EUR ING MRAeS) with over 15 years experience in the Aerospace, Defence and Rail Industry.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ashraf Miah

Data Scientist and Chartered Aeronautical Engineer (MEng CEng EUR ING MRAeS) with over 15 years experience in the Aerospace, Defence and Rail Industry.