environ
Environment & environment variable functions
load
load_env
The elevaso_spine.environ.load.load_env() function finds a .env file and loads the values into environment variables. This is helpful if you have multiple values for different environments that you want to test against.
For example, you have have a dev.env and test.env. When you call the elevaso_spine.environ.load.load_env() function you pass in the prefix which will load one of the two files.
By default, the function will look for .env file within 4 directories of the current project file calling elevaso_spine.environ.load.load_env().
- elevaso_spine.environ.load.load_env(prefix: str = None, path: str = None, overwrite: bool = False, search_dirs: int = 4)[source]
Load a .env file into Environment Variables
- Args:
prefix (str, Optional): Prefix of the file, defaults to None
Note
Useful if you want to have a dev.env, test.env, prod.env setup
path (str, Optional): Base path to start searching for env files, defaults to None
Note
If None, then will lookup the calling python functions path
overwrite (bool, Optional): True/False if existing environment variables should be overwritten by .env file content, defaults to False
search_dirs (int, Optional): Number of parent directories to traverse, defaults to 4
var
get_var
The elevaso_spine.environ.var.get_var() function retrieves an environment variable or returns a default value if not found.
- elevaso_spine.environ.var.get_var(name: str, default_val: object = None) object[source]
Retrieve environment variable value if exists
- Args:
name (str): Name of the environment variable
default_val (object, Optional): Default value to return, defaults to None
- Returns:
object: Python object value, or None if not exists
set_var
The elevaso_spine.environ.var.set_var() function creates or modifies an environment variable. It also provides the option to prevent overwrites or mocking the change.
- elevaso_spine.environ.var.set_var(name: str, val: str, overwrite: bool = False, set_val: bool = True) bool[source]
Set or update an environment variable
- Args:
name (str): Environment variable name
val (str): Value for the environment variable
overwrite (bool, Optional): Determines if value should be overwritten if Variable already exists, defaults to False
set_val (bool, Optional): Determines if the value should be set or just “mocked”, defaults to True
- Returns:
bool: True/False if successfully updated