File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -338,6 +338,7 @@ def dotenv_values(
338338 verbose : bool = False ,
339339 interpolate : bool = True ,
340340 encoding : Optional [str ] = "utf-8" ,
341+ with_env : bool = False ,
341342) -> Dict [str , Optional [str ]]:
342343 """
343344 Parse a .env file and return its content as a dict.
@@ -348,17 +349,25 @@ def dotenv_values(
348349 `False`.
349350 in `.env` file. Defaults to `False`.
350351 - *encoding*: encoding to be used to read the file.
352+ - *with_env*: include the os.environ() to response.
351353
352354 If both `dotenv_path` and `stream`, `find_dotenv()` is used to find the .env file.
353355 """
354356 if dotenv_path is None and stream is None :
355357 dotenv_path = find_dotenv ()
356358
357- return DotEnv (
359+ result = DotEnv (
358360 dotenv_path = dotenv_path ,
359361 stream = stream ,
360362 verbose = verbose ,
361363 interpolate = interpolate ,
362364 override = True ,
363365 encoding = encoding ,
364366 ).dict ()
367+ if with_env :
368+ return dict (
369+ ** os .environ ,
370+ ** result ,
371+ )
372+ else :
373+ return result
Original file line number Diff line number Diff line change @@ -384,3 +384,9 @@ def test_dotenv_values_file_stream(dotenv_file):
384384 result = dotenv .dotenv_values (stream = f )
385385
386386 assert result == {"a" : "b" }
387+
388+
389+ def test_dotenv_values_with_os_environment ():
390+ if os .environ .get ("USER" ):
391+ assert "USER" not in dotenv .dotenv_values (with_env = False )
392+ assert "USER" in dotenv .dotenv_values (with_env = True )
You can’t perform that action at this time.
0 commit comments