Parse a .env file and then load all the variables found as environment variables. Parameters: dotenv_path: Absolute or relative path to .env file. stream: Text stream (such as `io.StringIO`) with .env content, used if `dotenv_path` is `None`. verbose: Whether
(
dotenv_path: Optional[StrPath] = None,
stream: Optional[IO[str]] = None,
verbose: bool = False,
override: bool = False,
interpolate: bool = True,
encoding: Optional[str] = "utf-8",
)
| 381 | |
| 382 | |
| 383 | def load_dotenv( |
| 384 | dotenv_path: Optional[StrPath] = None, |
| 385 | stream: Optional[IO[str]] = None, |
| 386 | verbose: bool = False, |
| 387 | override: bool = False, |
| 388 | interpolate: bool = True, |
| 389 | encoding: Optional[str] = "utf-8", |
| 390 | ) -> bool: |
| 391 | """Parse a .env file and then load all the variables found as environment variables. |
| 392 | |
| 393 | Parameters: |
| 394 | dotenv_path: Absolute or relative path to .env file. |
| 395 | stream: Text stream (such as `io.StringIO`) with .env content, used if |
| 396 | `dotenv_path` is `None`. |
| 397 | verbose: Whether to output a warning the .env file is missing. |
| 398 | override: Whether to override the system environment variables with the variables |
| 399 | from the `.env` file. |
| 400 | encoding: Encoding to be used to read the file. |
| 401 | Returns: |
| 402 | Bool: True if at least one environment variable is set else False |
| 403 | |
| 404 | If both `dotenv_path` and `stream` are `None`, `find_dotenv()` is used to find the |
| 405 | .env file with it's default parameters. If you need to change the default parameters |
| 406 | of `find_dotenv()`, you can explicitly call `find_dotenv()` and pass the result |
| 407 | to this function as `dotenv_path`. |
| 408 | |
| 409 | If the environment variable `PYTHON_DOTENV_DISABLED` is set to a truthy value, |
| 410 | .env loading is disabled. |
| 411 | """ |
| 412 | if _load_dotenv_disabled(): |
| 413 | logger.debug( |
| 414 | "python-dotenv: .env loading disabled by PYTHON_DOTENV_DISABLED environment variable" |
| 415 | ) |
| 416 | return False |
| 417 | |
| 418 | if dotenv_path is None and stream is None: |
| 419 | dotenv_path = find_dotenv() |
| 420 | |
| 421 | dotenv = DotEnv( |
| 422 | dotenv_path=dotenv_path, |
| 423 | stream=stream, |
| 424 | verbose=verbose, |
| 425 | interpolate=interpolate, |
| 426 | override=override, |
| 427 | encoding=encoding, |
| 428 | ) |
| 429 | return dotenv.set_as_environment_variables() |
| 430 | |
| 431 | |
| 432 | def dotenv_values( |
searching dependent graphs…