zut.load_env

zut.load_env(path: Path | str = None, *, encoding='utf-8', override=False, from_dir=False)

Load the given file (or .env file found from the given or current directory) to environment variables.

  • If from_dir is True, path is a directory or file from which we will try to find the .env file.

Usage example:

` # Load configuration file load_env() # ... from the current working directory or its parents load_env(__file__, from_dir=True) #... from the Python module installation directory or its parents load_env(f'C:\ProgramData\my-app\my-app.env' if sys.platform == 'win32' else f'/etc/my-app/my-app.env') # .. from system configuration directory `