Skip to content

Commit b4e0c78

Browse files
authored
Docs: Improve documentation for variables without value (#390)
1 parent 07a2fa1 commit b4e0c78

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,20 @@ second line"
180180
FOO="first line\nsecond line"
181181
```
182182

183+
### Variable without a value
184+
185+
A variable can have no value:
186+
187+
```bash
188+
FOO
189+
```
190+
191+
It results in `dotenv_values` associating that variable name with the value `None` (e.g.
192+
`{"FOO": None}`. `load_dotenv`, on the other hand, simply ignores such variables.
193+
194+
This shouldn't be confused with `FOO=`, in which case the variable is associated with the
195+
empty string.
196+
183197
### Variable expansion
184198

185199
Python-dotenv can interpolate variables using POSIX variable expansion.

src/dotenv/main.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -351,14 +351,20 @@ def dotenv_values(
351351
"""
352352
Parse a .env file and return its content as a dict.
353353
354-
- *dotenv_path*: absolute or relative path to .env file.
355-
- *stream*: `StringIO` object with .env content, used if `dotenv_path` is `None`.
356-
- *verbose*: whether to output a warning the .env file is missing. Defaults to
354+
The returned dict will have `None` values for keys without values in the .env file.
355+
For example, `foo=bar` results in `{"foo": "bar"}` whereas `foo` alone results in
356+
`{"foo": None}`
357+
358+
Parameters:
359+
360+
- `dotenv_path`: absolute or relative path to the .env file.
361+
- `stream`: `StringIO` object with .env content, used if `dotenv_path` is `None`.
362+
- `verbose`: whether to output a warning if the .env file is missing. Defaults to
357363
`False`.
358-
in `.env` file. Defaults to `False`.
359-
- *encoding*: encoding to be used to read the file.
364+
- `encoding`: encoding to be used to read the file. Defaults to `"utf-8"`.
360365
361-
If both `dotenv_path` and `stream`, `find_dotenv()` is used to find the .env file.
366+
If both `dotenv_path` and `stream` are `None`, `find_dotenv()` is used to find the
367+
.env file.
362368
"""
363369
if dotenv_path is None and stream is None:
364370
dotenv_path = find_dotenv()

0 commit comments

Comments
 (0)