File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed
Filter options
Expand file tree Collapse file tree 2 files changed +16
-1
lines changed
Original file line number Diff line number Diff line change @@ -347,6 +347,7 @@ def dotenv_values(
347
347
verbose : bool = False ,
348
348
interpolate : bool = True ,
349
349
encoding : Optional [str ] = "utf-8" ,
350
+ with_env : bool = False ,
350
351
) -> Dict [str , Optional [str ]]:
351
352
"""
352
353
Parse a .env file and return its content as a dict.
@@ -362,18 +363,26 @@ def dotenv_values(
362
363
- `verbose`: whether to output a warning if the .env file is missing. Defaults to
363
364
`False`.
364
365
- `encoding`: encoding to be used to read the file. Defaults to `"utf-8"`.
366
+ - `with_env`: include the os.environ() to response.
365
367
366
368
If both `dotenv_path` and `stream` are `None`, `find_dotenv()` is used to find the
367
369
.env file.
368
370
"""
369
371
if dotenv_path is None and stream is None :
370
372
dotenv_path = find_dotenv ()
371
373
372
- return DotEnv (
374
+ result = DotEnv (
373
375
dotenv_path = dotenv_path ,
374
376
stream = stream ,
375
377
verbose = verbose ,
376
378
interpolate = interpolate ,
377
379
override = True ,
378
380
encoding = encoding ,
379
381
).dict ()
382
+ if with_env :
383
+ return dict (
384
+ ** os .environ ,
385
+ ** result ,
386
+ )
387
+ else :
388
+ return result
Original file line number Diff line number Diff line change @@ -415,3 +415,9 @@ def test_dotenv_values_file_stream(dotenv_file):
415
415
result = dotenv .dotenv_values (stream = f )
416
416
417
417
assert result == {"a" : "b" }
418
+
419
+
420
+ def test_dotenv_values_with_os_environment ():
421
+ if os .environ .get ("USER" ):
422
+ assert "USER" not in dotenv .dotenv_values (with_env = False )
423
+ assert "USER" in dotenv .dotenv_values (with_env = True )
You can’t perform that action at this time.
0 commit comments