Package: secret-garden
secret-gardenA better way to manage your dotenv variablesInstallationYou can use your most preferred package manager to install the packagepip install secret-gardenorpoetry add secret-garden...Table of ContentsUsageloading from a fileloading from the environment namespaceloading from a file using the environment namespace as an alternativeExamplesUsing a fileenvjsontomlyamlUsing the environment namespaceObjectsloadload_fileload_spaceUpcoming FeaturesUsageYou can put your variables in a file or use the environment namespaceLoading from a fileCreate a file using one of the following formats and add your variables:.env.json.yaml.tomlNote: When using the.envfile, the variables should be declared as python variablesUse theload_filefunction to load the variables, specifying the format of the filefromsecret_gardenimportload_fileload_file('path/to/your/file',format_='<your_format>')Pass the globals dictionary if you want to load the variables into the global namespacefromsecret_gardenimportload_fileload_file('path/to/your/file',format_='<your_format>',globals_=globals())Loading from the environment namespaceAdd your variables into the environment namespaceexportSTR_VAR="string"exportINT_VAR=1exportFLOAT_VAR='1.0'exportBOOL_VAR=TrueexportLIST_VAR="['item1', 'item2']"exportDICT_VAR="{'key1': 'value1', 'key2': 'value2'}"Use theload_spacefunction to load the variablesfromsecret_gardenimportload_spaceload_space(['STR_VAR','INT_VAR','FLOAT_VAR','BOOL_VAR','LIST_VAR','DICT_VAR'])Pass the globals dictionary if you want to load the variables into the global namespacefromsecret_gardenimportload_spaceload_space(['STR_VAR','INT_VAR','FLOAT_VAR','BOOL_VAR','LIST_VAR','DICT_VAR'],globals_=globals())Loading from a file using the environment namespace as an alternativeThis is done using theloadfunction by declaring in order:the path to the file containing the variablesthe variables to be included from the environment namespaceIf both path and include are provided, the variables are loaded from the file and the include argument is ignored.fromsecret_gardenimportloadload("/path/to/your/file",# path to the file containing the variables["VAR1","VAR2"],# this will be ignoredformat_='env',globals_=None,)If path does not exist, the variables are loaded from the environment namespace. The include argument is used to know which variables to get from the environment namespace.fromsecret_gardenimportloadload("/path/to/the/non-existent/file",# path to the non-existent file["VAR1","VAR2"],# variables to be included from the environment namespaceformat_='env',globals_=None,)ExamplesUsing a fileenvAdd your variables into the.envfileSTR_VAR="string"INT_VAR=1FLOAT_VAR=1.0BOOL_VAR=TrueLIST_VAR=['item1','item2']DICT_VAR={'key1':'value1','key2':'value2'}Use theload_filefunction to load the variablesfromsecret_gardenimportload_fileload_file('path/to/your/file.env',format_='env')Using theglobals_parameterfromsecret_gardenimportload_fileload_file('path/to/your/.env',format_='env',globals_=globals())jsonAdd your variables into the.jsonfile{"STR_VAR":"string","INT_VAR":1,"FLOAT_VAR":1.0,"BOOL_VAR":true,"LIST_VAR":["item1","item2"],"DICT_VAR":{"key1":"value1","key2":"value2"}}Use theload_filefunction to load the variablesfromsecret_gardenimportload_fileload_file('path/to/your/file.json',format_='json')Using theglobals_parameterfromsecret_gardenimportload_fileload_file('path/to/your/file.json',format_='json',globals_=globals())tomlAdd your variables into the.tomlfileSTR_VAR="string"INT_VAR=1FLOAT_VAR=1.0BOOL_VAR=trueLIST_VAR=["item1","item2"]DICT_VAR={key1="value1",key2="value2"}Use theload_filefunction to load the variablesfromsecret_gardenimportload_fileload_file('path/to/your/file.toml',format_='toml')Using theglobals_parameterfromsecret_gardenimportload_fileload_file('path/to/your/file.toml',format_='toml',globals_=globals())yamlAdd your variables into the.yamlfileSTR_VAR:stringINT_VAR:1FLOAT_VAR:1.0BOOL_VAR:trueLIST_VAR:-item1-item2DICT_VAR:key1:value1key2:value2Use theload_filefunction to load the variablesfromsecret_gardenimportload_fileload_file('path/to/your/file.yaml',format_='yaml')Using theglobals_parameterfromsecret_gardenimportload_fileload_file('path/to/your/file.yaml',format_='yaml',globals_=globals())Using the environment namespaceAdd your variables into the environment namespaceexportSTR_VAR="string"exportINT_VAR=1exportFLOAT_VAR=1.0exportBOOL_VAR=TrueexportLIST_VAR="['item1', 'item2']"exportDICT_VAR="{'key1': 'value1', 'key2': 'value2'}"Use theload_spacefunction to load the variablesfromsecret_gardenimportload_spaceload_space(['STR_VAR','INT_VAR','FLOAT_VAR','BOOL_VAR','LIST_VAR','DICT_VAR'])Using theglobals_parameterfromsecret_gardenimportload_spaceload_space(['STR_VAR','INT_VAR','FLOAT_VAR','BOOL_VAR','LIST_VAR','DICT_VAR'],globals_=globals())Objectsloadload(path_or_include:Path|PathLike|str|list[str],# path to the file or a list of variables to be included from the environment namespaceformat_:str='environ',# the format of the file if path_or_include is a pathglobals_:dict=None,# the execution global namespace to load the variables into)If both path and include are provided, the variables are loaded from the file and the include argument is ignoredIf path does not exist, the variables are loaded from the environment namespace and the include argument is used to filter the variables.path(Path | PathLike | str): The path to the file containing the environment variablesinclude(list[str]): The variables to include when loading from the environment namespaceformat_- Format of the file containing the variables.It can be one of the following:'env' -Variables are declared as python variables'environ' -Variables are declared as environment variables where value are in quotes'json''yaml''toml'globals_- If not provided, variables will returned as a dictionaryload_fileload_file(path:str,# path to the fileformat_:str='environ',# the format of the fileglobals_:dict=None,# the execution global namespace to load the variables into)path- The path to the file containing the variablesformat_- Format of the file containing the variables.It can be one of the following:'env' -Variables are declared as python variables'json''yaml''toml'globals_- If not provided, variables will returned as a dictionaryload_spaceload_space(include:list,# a list of variables to be included from the environment namespaceglobals_:dict=None,# the execution global namespace to load the variables into)include- A list of variables to be included from the environment namespaceglobals_- If not provided, variables will returned as a dictionaryUpcoming FeaturesSupport for multiline declaration in the'env'and'environ'formatsSupport for nested dictionary and list types in the'env'and'environ'formats