MCPcopy Index your code
hub / github.com/theskumar/python-dotenv / dotenv_values

Function dotenv_values

src/dotenv/main.py:432–465  ·  view source on GitHub ↗

Parse a .env file and return its content as a dict. The returned dict will have `None` values for keys without values in the .env file. For example, `foo=bar` results in `{"foo": "bar"}` whereas `foo` alone results in `{"foo": None}` Parameters: dotenv_path: Absolute o

(
    dotenv_path: Optional[StrPath] = None,
    stream: Optional[IO[str]] = None,
    verbose: bool = False,
    interpolate: bool = True,
    encoding: Optional[str] = "utf-8",
)

Source from the content-addressed store, hash-verified

430
431
432def dotenv_values(
433 dotenv_path: Optional[StrPath] = None,
434 stream: Optional[IO[str]] = None,
435 verbose: bool = False,
436 interpolate: bool = True,
437 encoding: Optional[str] = "utf-8",
438) -> Dict[str, Optional[str]]:
439 """
440 Parse a .env file and return its content as a dict.
441
442 The returned dict will have `None` values for keys without values in the .env file.
443 For example, `foo=bar` results in `{"foo": "bar"}` whereas `foo` alone results in
444 `{"foo": None}`
445
446 Parameters:
447 dotenv_path: Absolute or relative path to the .env file.
448 stream: `StringIO` object with .env content, used if `dotenv_path` is `None`.
449 verbose: Whether to output a warning if the .env file is missing.
450 encoding: Encoding to be used to read the file.
451
452 If both `dotenv_path` and `stream` are `None`, `find_dotenv()` is used to find the
453 .env file.
454 """
455 if dotenv_path is None and stream is None:
456 dotenv_path = find_dotenv()
457
458 return DotEnv(
459 dotenv_path=dotenv_path,
460 stream=stream,
461 verbose=verbose,
462 interpolate=interpolate,
463 override=True,
464 encoding=encoding,
465 ).dict()
466
467
468def _is_file_or_fifo(path: StrPath) -> bool:

Callers 3

list_valuesFunction · 0.85
getFunction · 0.85
runFunction · 0.85

Calls 3

find_dotenvFunction · 0.85
DotEnvClass · 0.85
dictMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…