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

add DotEnv dumps/dump #503

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

mattwwarren
Copy link

fixes #502

@@ -113,6 +113,43 @@ def get(self, key: str) -> Optional[str]:

return None

def from_dict(self, data: Dict[str, Optional[str]], override: bool = False) -> None:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this should be a classmethod

@AMDphreak
Copy link

AMDphreak commented Nov 26, 2024

How does this code snippet write anything to the .env file? I see no file write operation.

People just want to read and write. Don't need to 'dump' just write. Write one, two, or some dict of variables. The library should have an function for users to add to its dict, and a way to write new items to the file.

During the process of writing to the file, add the items to the dict. Do not require programmers to first add them to the lib's dict and then explicitly write them to the file. The intuition of the programmer is that this lib has a direct connection to the .env file, so they shouldn't even know that you have a dict in memory.

main API calls:
load_dotenv() (since you chose load over read)
write_dotenv(dict[]) <- equivalent to add_var() but also writes the file. Assumption is the programmer wants to append to .env file.

special use functions:
add_var(dict) <- puts var in dict but doesn't write the file.
add_var(dict[]) <- Just overload it. I know it's not plural but programmers like consistency. this would be for someone who for some reason needs to write lots of vars without
rem_var(dict) <- removes item from array with arrayname.remove() function
rem_var(dict[]) <- not plural but overload it.

I would like to use the .env variable to store settings from a user, since the programmer can provide an API key, or the user can provide an API key. I suppose this isn't the usual way to do things, but this is simpler for me than creating files in The user folder or AppData.

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

Successfully merging this pull request may close these issues.

Support for dumping to a .env file?
2 participants