Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to create environment variables from .env file while still consuming it in the settings class #226

Closed
gwdekker opened this issue Feb 1, 2024 · 2 comments
Assignees

Comments

@gwdekker
Copy link

gwdekker commented Feb 1, 2024

My use case is the following.

I have a project, which uses pydantic-settings to gather a bunch of different settings. Very useful, very neat solution (getting rid of environment variables being imported everywhere is awesome. In addition, it provides an excellent way of documenting environment variables needed to run the project).

Some of my settings are read from a .env file, and I believed I could get rid of a load_dotenv() call in my code.

However, a dependency of my project also needs some of my settings, and expects them as an environment variable!

My feature request: could the SettingsConfigDict get a boolean to toggle whether if providing a .env file, the variables in the .env file get consumed (current behavior), or in addition get provided as environment variables (like what load_dotenv() does?) Or would you judge this too much of an edge case to add another setting to the dict?

Keep up the great work, there are not many days spent coding nowadays where I do not either touch a normal pydantic class or a pydantic-settings object!

@hramezani
Copy link
Member

@gwdekker
Here is my understanding of this feature request. you need a flag to read the env variables from a dotenv file and set them as env variables for other projects. this is really an edge case and I would say it would be good to you implement it in your own project.

@gwdekker
Copy link
Author

gwdekker commented Feb 2, 2024

ok fair enough - thanks for taking the time to answer, highly appreciated!

@gwdekker gwdekker closed this as completed Feb 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants