secret-garden
A better way to manage your dotenv variables
Installation
-
You can use your most preferred package manager to install the package
pip install secret-gardenorpoetry add secret-garden...
Table of Contents
Usage
You can put your variables in a file or use the environment namespace
Loading from a file
Create 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 variables
Use the load_file function to load the variables, specifying the format of the file
from secret_garden import load_file
load_file('path/to/your/file', format_='<your_format>')
Pass the globals dictionary if you want to load the variables into the global namespace
from secret_garden import load_file
load_file(
'path/to/your/file',
format_='<your_format>',
globals_=globals()
)
Loading from the environment namespace
Add your variables into the environment namespace
export STR_VAR="string"
export INT_VAR=1
export FLOAT_VAR='1.0'
export BOOL_VAR=True
export LIST_VAR="['item1', 'item2']"
export DICT_VAR="{'key1': 'value1', 'key2': 'value2'}"
Use the load_space function to load the variables
from secret_garden import load_space
load_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 namespace
from secret_garden import load_space
load_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 alternative
-
This is done using the
loadfunction by declaring in order:- the path to the file containing the variables
- the variables to be included from the environment namespace
-
If both path and include are provided, the variables are loaded from the file and the include argument is ignored.
from secret_garden import load load( "/path/to/your/file", # path to the file containing the variables ["VAR1", "VAR2"], # this will be ignored format_ = '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.
from secret_garden import load load( "/path/to/the/non-existent/file", # path to the non-existent file ["VAR1", "VAR2"], # variables to be included from the environment namespace format_ = 'env', globals_ = None, )
Examples
Using a file
env
-
Add your variables into the
.envfileSTR_VAR="string" INT_VAR=1 FLOAT_VAR=1.0 BOOL_VAR=True LIST_VAR=['item1', 'item2'] DICT_VAR={'key1': 'value1', 'key2': 'value2'}
-
Use the
load_filefunction to load the variablesfrom secret_garden import load_file load_file('path/to/your/file.env', format_='env')
-
Using the
globals_parameterfrom secret_garden import load_file load_file( 'path/to/your/.env', format_='env', globals_=globals() )
json
-
Add 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 the
load_filefunction to load the variablesfrom secret_garden import load_file load_file('path/to/your/file.json', format_='json')
-
Using the
globals_parameterfrom secret_garden import load_file load_file( 'path/to/your/file.json', format_='json', globals_=globals() )
toml
-
Add your variables into the
.tomlfileSTR_VAR = "string" INT_VAR = 1 FLOAT_VAR = 1.0 BOOL_VAR = true LIST_VAR = ["item1", "item2"] DICT_VAR = {key1 = "value1", key2 = "value2"}
-
Use the
load_filefunction to load the variablesfrom secret_garden import load_file load_file('path/to/your/file.toml', format_='toml')
-
Using the
globals_parameterfrom secret_garden import load_file load_file( 'path/to/your/file.toml', format_='toml', globals_=globals() )
yaml
-
Add your variables into the
.yamlfileSTR_VAR: string INT_VAR: 1 FLOAT_VAR: 1.0 BOOL_VAR: true LIST_VAR: - item1 - item2 DICT_VAR: key1: value1 key2: value2
-
Use the
load_filefunction to load the variablesfrom secret_garden import load_file load_file('path/to/your/file.yaml', format_='yaml')
-
Using the
globals_parameterfrom secret_garden import load_file load_file( 'path/to/your/file.yaml', format_='yaml', globals_=globals() )
Using the environment namespace
-
Add your variables into the environment namespace
export STR_VAR="string" export INT_VAR=1 export FLOAT_VAR=1.0 export BOOL_VAR=True export LIST_VAR="['item1', 'item2']" export DICT_VAR="{'key1': 'value1', 'key2': 'value2'}"
-
Use the
load_spacefunction to load the variablesfrom secret_garden import load_space load_space(['STR_VAR', 'INT_VAR', 'FLOAT_VAR', 'BOOL_VAR', 'LIST_VAR', 'DICT_VAR'])
-
Using the
globals_parameterfrom secret_garden import load_space load_space( ['STR_VAR', 'INT_VAR', 'FLOAT_VAR', 'BOOL_VAR', 'LIST_VAR', 'DICT_VAR'], globals_=globals() )
Objects
-
loadload( path_or_include: Path | PathLike | str | list[str], # path to the file or a list of variables to be included from the environment namespace format_: str = 'environ', # the format of the file if path_or_include is a path globals_: 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 ignored
If 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 dictionary
-
load_fileload_file( path: str, # path to the file format_: str = 'environ', # the format of the file globals_: 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 dictionary
-
load_spaceload_space( include: list, # a list of variables to be included from the environment namespace globals_: 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 dictionary
Upcoming Features
-
Support for multiline declaration in the
'env'and'environ'formats -
Support for nested dictionary and list types in the
'env'and'environ'formats
Release files for secret-garden 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| secret_garden-1.0.1.tar.gz | 8.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| secret_garden-1.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 16.4 kB
Release files / secret_garden-1.0.1.tar.gz
| Download URL | secret_garden-1.0.1.tar.gz |
|---|---|
| Size | 8.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fcd57cf58ad595eda8fa2b7b01fd871b29876bcd41e766e6b50e67f5ecfa0086
|
|
BLAKE2b-256 checksum How to use checksums |
6830a439643e4d2ae16e90b70d56ca02b06363136d091cd81044707b58de7359
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.1 CPython/3.10.13 Linux/6.2.0-1019-azure
|
Release files / secret_garden-1.0.1-py3-none-any.whl
| Download URL | secret_garden-1.0.1-py3-none-any.whl |
|---|---|
| Size | 8.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8995daccbe076390674324f7c58a9c242a214ae920efbb6164d876dd4d950526
|
|
BLAKE2b-256 checksum How to use checksums |
f6dd5664da07f2d8629d6238a00c0655fa414b3759002c6633ae2c187d64397d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.1 CPython/3.10.13 Linux/6.2.0-1019-azure
|