pydantic-argparse icon indicating copy to clipboard operation
pydantic-argparse copied to clipboard

Enhancement: Investigate `.env` file support

Open SupImDos opened this issue 1 year ago • 0 comments

Summary

  • As raised by @ericchansen in #34, pydantic-argparse should be able to piggy-back off pydantic and support loading environment variables from .env files.
  • This can probably be accomplished by defining arguments as shown below:
    class Args(pydantic.BaseSettings):
        my_arg: int = pydantic.Field(description="this is an int")
    
        class Config:
            env_file = ".env"
            env_file_encoding = "utf-8"
    
  • See: https://docs.pydantic.dev/latest/usage/settings/#dotenv-env-support
  • If this does work, it might be nice to provide a dotenv extra for pydantic-argparse (similar to pydantic) so people can install it with:
    $ pip install pydantic-argparse[dotenv]
    

SupImDos avatar May 26 '23 00:05 SupImDos