Package: pydotenvs
PY.EnvImport environment variables from your .env file or run as command line tool; PyDotEnv Cli.Python 3Command line toolVersionStable: v0.2.0How to usepipinstallpydotenvs

orgitclonehttps://github.com/ableinc/pyenv.gitcdpyenv
pipinstall--editable.Now import into any python project you havefrompydotenvsimportload_envload_env()orload_env('.myEnvFile')orenvObj=load_env_object()envObj['myEnv']# NewenvObj=load_env_object(values_as_datatype=True)envObj['myEnv']# The example above will return the values in the dictionary as their respective data types.That's it!DemoRun this to see a working examplepythonexample/demo.pyStringIOYou can load your local .env file as a StringIO object.
By default you are responsible for closing the StringIO
object. Though, there is an option to auto close upon program
termination.frompydotenvsimportload_envstringObj=load_env(stringIO=True,auto_close=True)contents=stringObj.getvalue()TransferYou can now transfer an existing .env file variables to a new .env file,
with the option of preserving or overriding the existing values in the new
.env file. You can use this feature via the CLI tool or by importing the
function from the pydotenvs library. Preserve is True by default. Example:frompydotenvsimporttransfer_new_env,load_envtransfer_new_env(old_env_path='.env',new_env_path='.env-new',preserve=True)# load_env('.env-new')orpyenv-f.env-n.newenv-tTrueClearYou can clear environment variables during runtime with theclear_envfunction. You can provide the .env file path or use the default file path.
If you've ran a transfer during the current runtime, it will only remove the
variables set in the new environment variable file. By default it will only
clear the environment variables set in the .env file path provided. Example:frompydotenvsimportclear_envclear_env(env_path='.env',module_init_only=True)Command Line Tool - CLIYou can use PyEnv as a command line tool. All the same features apply.
It would be common to use the client tool for the Dictionary & StringIO
features of PyEnv.You can run a command that requires your local environment variables
with PyEnv command line tool. Your variables will only exist in
that one instance.pyenv--command'echo $MY_VARIABLE'Usage:pyenv[OPTIONS]Options:-f,--envpathPATHLocationof.envfile,defaultsto.envincurrentworkingdirectory[required]-n,--newpathPATHLocationofnew.envfilethatyouwouldliketotransferoldenvfilevariablesto-t,--transferBOOLEANThismustbetrueifyouwouldliketotransfer.--newpathisrequiredaswell.-p,--preserveBOOLEANTrueorFalsewhetherornottopreserveexistingenvsduringtransfer-c,--commandTEXTRunacommandthatrequireslocalenviornmentvariablesforoneinstance-l,--loadobjBOOLEANLoad.envfileasobjectinsteadofenvironmentvariable-s,--stringioBOOLEANLoad.envfileasStringIOobjectinsteadofenvironmentvariable--clearBOOLEANCleartheenvironmentvariablessetbypydotenvsorallvariablesduringruntime.-v,--verboseBOOLEANVerbose--versionShowtheversionandexit.--helpShowthismessageandexit.ChangelogJuly 2022 - Minor version updateWhen usingload_env_object()you can now return the values as their respective data type. i.eload_env_object('.env', values_as_datatype=True)(Note: default is False. Data types supported are integer, float, dictionary, string, and list.)Squashed some bugs :)March 2022 - Minor version udpateBug fix where 'PWD' key was not found on linux systems.January 2022 - Minfor version updateYou can now transfer an old .env file document to a new .env file document. Described above.Before, the .env file was required at root of the project directory. This is no longer the case, you
can now give any file path on the system.Option to clear all environment variables or only the ones imported by pydotenvs - Default: module_init_only=TrueOctober 2020 - Minor version updateAny message that should/shall be printed (unrelated to an error) will be controlled by the boolean value of verbose.Cleaned the CLI code, slightly