Skip to content

Commit 13b0fed

Browse files
disable dotenv_values if DOTENV_AUTOLOAD_DISABLED is set to a true value
1 parent 666984d commit 13b0fed

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

src/dotenv/main.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,9 @@ def load_dotenv(
350350
of `find_dotenv()`, you can explicitly call `find_dotenv()` and pass the result
351351
to this function as `dotenv_path`.
352352
"""
353+
if _dotenv_autoload_disabled():
354+
return False
355+
353356
if dotenv_path is None and stream is None:
354357
dotenv_path = find_dotenv()
355358

@@ -398,3 +401,12 @@ def dotenv_values(
398401
override=True,
399402
encoding=encoding,
400403
).dict()
404+
405+
def _dotenv_autoload_disabled() -> bool:
406+
"""
407+
Determine if dotenv autoloading has been disabled.
408+
"""
409+
if "DOTENV_AUTOLOAD_DISABLED" not in os.environ:
410+
return False
411+
value = os.environ["DOTENV_AUTOLOAD_DISABLED"].casefold()
412+
return value in {"1", "true", "t", "yes", "y"}

0 commit comments

Comments
 (0)