MCPcopy Create free account
hub / github.com/theskumar/python-dotenv / dotenv_values

Function dotenv_values

src/dotenv/main.py:349–382  ·  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

347
348
349def dotenv_values(
350 dotenv_path: Optional[StrPath] = None,
351 stream: Optional[IO[str]] = None,
352 verbose: bool = False,
353 interpolate: bool = True,
354 encoding: Optional[str] = "utf-8",
355) -> Dict[str, Optional[str]]:
356 """
357 Parse a .env file and return its content as a dict.
358
359 The returned dict will have `None` values for keys without values in the .env file.
360 For example, `foo=bar` results in `{"foo": "bar"}` whereas `foo` alone results in
361 `{"foo": None}`
362
363 Parameters:
364 dotenv_path: Absolute or relative path to the .env file.
365 stream: `StringIO` object with .env content, used if `dotenv_path` is `None`.
366 verbose: Whether to output a warning if the .env file is missing.
367 encoding: Encoding to be used to read the file.
368
369 If both `dotenv_path` and `stream` are `None`, `find_dotenv()` is used to find the
370 .env file.
371 """
372 if dotenv_path is None and stream is None:
373 dotenv_path = find_dotenv()
374
375 return DotEnv(
376 dotenv_path=dotenv_path,
377 stream=stream,
378 verbose=verbose,
379 interpolate=interpolate,
380 override=True,
381 encoding=encoding,
382 ).dict()

Callers 3

listFunction · 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