Skip to content

Commit df2f66d

Browse files
committed
docs: clarify override behavior and document FIFO support
- Explicitly state that override=False is the default behavior in the Getting Started section for better clarity - Add note about FIFO (named pipes) support on Unix systems in the File format section - Improve formatting consistency: - Standardize TOC list markers (use '-' instead of '*') - Fix line wrapping and spacing issues throughout
1 parent c8de288 commit df2f66d

File tree

1 file changed

+70
-66
lines changed

1 file changed

+70
-66
lines changed

README.md

Lines changed: 70 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
[![Build Status][build_status_badge]][build_status_link]
44
[![PyPI version][pypi_badge]][pypi_link]
55

6-
python-dotenv reads key-value pairs from a `.env` file and can set them as environment
7-
variables. It helps in the development of applications following the
6+
python-dotenv reads key-value pairs from a `.env` file and can set them as
7+
environment variables. It helps in the development of applications following the
88
[12-factor](https://12factor.net/) principles.
99

1010
- [Getting Started](#getting-started)
1111
- [Other Use Cases](#other-use-cases)
12-
* [Load configuration without altering the environment](#load-configuration-without-altering-the-environment)
13-
* [Parse configuration as a stream](#parse-configuration-as-a-stream)
14-
* [Load .env files in IPython](#load-env-files-in-ipython)
12+
- [Load configuration without altering the environment](#load-configuration-without-altering-the-environment)
13+
- [Parse configuration as a stream](#parse-configuration-as-a-stream)
14+
- [Load .env files in IPython](#load-env-files-in-ipython)
1515
- [Command-line Interface](#command-line-interface)
1616
- [File format](#file-format)
17-
* [Multiline values](#multiline-values)
18-
* [Variable expansion](#variable-expansion)
17+
- [Multiline values](#multiline-values)
18+
- [Variable expansion](#variable-expansion)
1919
- [Related Projects](#related-projects)
2020
- [Acknowledgements](#acknowledgements)
2121

@@ -25,13 +25,13 @@ variables. It helps in the development of applications following the
2525
pip install python-dotenv
2626
```
2727

28-
If your application takes its configuration from environment variables, like a 12-factor
29-
application, launching it in development is not very practical because you have to set
30-
those environment variables yourself.
28+
If your application takes its configuration from environment variables, like a
29+
12-factor application, launching it in development is not very practical because
30+
you have to set those environment variables yourself.
3131

32-
To help you with that, you can add python-dotenv to your application to make it load the
33-
configuration from a `.env` file when it is present (e.g. in development) while remaining
34-
configurable via the environment:
32+
To help you with that, you can add python-dotenv to your application to make it
33+
load the configuration from a `.env` file when it is present (e.g. in
34+
development) while remaining configurable via the environment:
3535

3636
```python
3737
from dotenv import load_dotenv
@@ -46,18 +46,19 @@ By default, `load_dotenv()` will:
4646

4747
- Look for a `.env` file in the same directory as the Python script (or higher up the directory tree).
4848
- Read each key-value pair and add it to `os.environ`.
49-
- **Not override** an environment variable that is already set, unless you explicitly pass `override=True`.
49+
- **Not override** existing environment variables (`override=False`). Pass `override=True` to override existing variables.
5050

51-
To configure the development environment, add a `.env` in the root directory of your
52-
project:
51+
To configure the development environment, add a `.env` in the root directory of
52+
your project:
5353

5454
```
5555
.
5656
├── .env
5757
└── foo.py
5858
```
5959

60-
The syntax of `.env` files supported by python-dotenv is similar to that of Bash:
60+
The syntax of `.env` files supported by python-dotenv is similar to that of
61+
Bash:
6162

6263
```bash
6364
# Development settings
@@ -66,22 +67,21 @@ ADMIN_EMAIL=admin@${DOMAIN}
6667
ROOT_URL=${DOMAIN}/app
6768
```
6869

69-
If you use variables in values, ensure they are surrounded with `{` and `}`, like
70-
`${DOMAIN}`, as bare variables such as `$DOMAIN` are not expanded.
70+
If you use variables in values, ensure they are surrounded with `{` and `}`,
71+
like `${DOMAIN}`, as bare variables such as `$DOMAIN` are not expanded.
7172

72-
You will probably want to add `.env` to your `.gitignore`, especially if it contains
73-
secrets like a password.
73+
You will probably want to add `.env` to your `.gitignore`, especially if it
74+
contains secrets like a password.
7475

75-
See the section "File format" below for more information about what you can write in a
76-
`.env` file.
76+
See the section "[File format](#file-format)" below for more information about what you can write in a `.env` file.
7777

7878
## Other Use Cases
7979

8080
### Load configuration without altering the environment
8181

82-
The function `dotenv_values` works more or less the same way as `load_dotenv`, except it
83-
doesn't touch the environment, it just returns a `dict` with the values parsed from the
84-
`.env` file.
82+
The function `dotenv_values` works more or less the same way as `load_dotenv`,
83+
except it doesn't touch the environment, it just returns a `dict` with the
84+
values parsed from the `.env` file.
8585

8686
```python
8787
from dotenv import dotenv_values
@@ -104,9 +104,9 @@ config = {
104104

105105
### Parse configuration as a stream
106106

107-
`load_dotenv` and `dotenv_values` accept [streams][python_streams] via their `stream`
108-
argument. It is thus possible to load the variables from sources other than the
109-
filesystem (e.g. the network).
107+
`load_dotenv` and `dotenv_values` accept [streams][python_streams] via their
108+
`stream` argument. It is thus possible to load the variables from sources other
109+
than the filesystem (e.g. the network).
110110

111111
```python
112112
from io import StringIO
@@ -119,7 +119,7 @@ load_dotenv(stream=config)
119119

120120
### Load .env files in IPython
121121

122-
You can use dotenv in IPython. By default, it will use `find_dotenv` to search for a
122+
You can use dotenv in IPython. By default, it will use `find_dotenv` to search for a
123123
`.env` file:
124124

125125
```python
@@ -140,12 +140,14 @@ Optional flags:
140140

141141
### Disable load_dotenv
142142

143-
Set `PYTHON_DOTENV_DISABLED=1` to disable `load_dotenv()` from loading .env files or streams. Useful when you can't modify third-party package calls or in production.
143+
Set `PYTHON_DOTENV_DISABLED=1` to disable `load_dotenv()` from loading .env
144+
files or streams. Useful when you can't modify third-party package calls or in
145+
production.
144146

145147
## Command-line Interface
146148

147-
A CLI interface `dotenv` is also included, which helps you manipulate the `.env` file
148-
without manually opening it.
149+
A CLI interface `dotenv` is also included, which helps you manipulate the `.env`
150+
file without manually opening it.
149151

150152
```shell
151153
$ pip install "python-dotenv[cli]"
@@ -166,13 +168,13 @@ Run `dotenv --help` for more information about the options and subcommands.
166168

167169
## File format
168170

169-
The format is not formally specified and still improves over time. That being said,
170-
`.env` files should mostly look like Bash files.
171+
The format is not formally specified and still improves over time. That being
172+
said, `.env` files should mostly look like Bash files. Reading from FIFOs (named pipes) on Unix systems is also supported.
171173

172-
Keys can be unquoted or single-quoted. Values can be unquoted, single- or double-quoted.
173-
Spaces before and after keys, equal signs, and values are ignored. Values can be followed
174-
by a comment. Lines can start with the `export` directive, which does not affect their
175-
interpretation.
174+
Keys can be unquoted or single-quoted. Values can be unquoted, single- or
175+
double-quoted. Spaces before and after keys, equal signs, and values are
176+
ignored. Values can be followed by a comment. Lines can start with the `export`
177+
directive, which does not affect their interpretation.
176178

177179
Allowed escape sequences:
178180

@@ -181,8 +183,8 @@ Allowed escape sequences:
181183

182184
### Multiline values
183185

184-
It is possible for single- or double-quoted values to span multiple lines. The following
185-
examples are equivalent:
186+
It is possible for single- or double-quoted values to span multiple lines. The
187+
following examples are equivalent:
186188

187189
```bash
188190
FOO="first line
@@ -201,26 +203,27 @@ A variable can have no value:
201203
FOO
202204
```
203205

204-
It results in `dotenv_values` associating that variable name with the value `None` (e.g.
205-
`{"FOO": None}`. `load_dotenv`, on the other hand, simply ignores such variables.
206+
It results in `dotenv_values` associating that variable name with the value
207+
`None` (e.g. `{"FOO": None}`. `load_dotenv`, on the other hand, simply ignores
208+
such variables.
206209

207-
This shouldn't be confused with `FOO=`, in which case the variable is associated with the
208-
empty string.
210+
This shouldn't be confused with `FOO=`, in which case the variable is associated
211+
with the empty string.
209212

210213
### Variable expansion
211214

212215
python-dotenv can interpolate variables using POSIX variable expansion.
213216

214-
With `load_dotenv(override=True)` or `dotenv_values()`, the value of a variable is the
215-
first of the values defined in the following list:
217+
With `load_dotenv(override=True)` or `dotenv_values()`, the value of a variable
218+
is the first of the values defined in the following list:
216219

217220
- Value of that variable in the `.env` file.
218221
- Value of that variable in the environment.
219222
- Default value, if provided.
220223
- Empty string.
221224

222-
With `load_dotenv(override=False)`, the value of a variable is the first of the values
223-
defined in the following list:
225+
With `load_dotenv(override=False)`, the value of a variable is the first of the
226+
values defined in the following list:
224227

225228
- Value of that variable in the environment.
226229
- Value of that variable in the `.env` file.
@@ -229,26 +232,27 @@ defined in the following list:
229232

230233
## Related Projects
231234

232-
- [Honcho](https://github.com/nickstenning/honcho) - For managing
233-
Procfile-based applications.
234-
- [django-dotenv](https://github.com/jpadilla/django-dotenv)
235-
- [django-environ](https://github.com/joke2k/django-environ)
236-
- [django-configuration](https://github.com/jezdez/django-configurations)
237-
- [dump-env](https://github.com/sobolevn/dump-env)
238-
- [environs](https://github.com/sloria/environs)
239-
- [dynaconf](https://github.com/dynaconf/dynaconf)
240-
- [parse_it](https://github.com/naorlivne/parse_it)
241-
- [python-decouple](https://github.com/HBNetwork/python-decouple)
235+
- [environs](https://github.com/sloria/environs)
236+
- [Honcho](https://github.com/nickstenning/honcho)
237+
- [dump-env](https://github.com/sobolevn/dump-env)
238+
- [dynaconf](https://github.com/dynaconf/dynaconf)
239+
- [parse_it](https://github.com/naorlivne/parse_it)
240+
- [django-dotenv](https://github.com/jpadilla/django-dotenv)
241+
- [django-environ](https://github.com/joke2k/django-environ)
242+
- [python-decouple](https://github.com/HBNetwork/python-decouple)
243+
- [django-configuration](https://github.com/jezdez/django-configurations)
242244

243245
## Acknowledgements
244246

245-
This project is currently maintained by [Saurabh Kumar](https://saurabh-kumar.com) and
246-
[Bertrand Bonnefoy-Claudet](https://github.com/bbc2) and would not have been possible
247-
without the support of these [awesome
248-
people](https://github.com/theskumar/python-dotenv/graphs/contributors).
247+
This project is currently maintained by [Saurabh Kumar][saurabh-homepage] and
248+
[Bertrand Bonnefoy-Claudet][gh-bbc2] and would not have been possible without
249+
the support of these [awesome people][contributors].
249250

250-
[build_status_badge]: https://github.com/theskumar/python-dotenv/actions/workflows/test.yml/badge.svg
251-
[build_status_link]: https://github.com/theskumar/python-dotenv/actions/workflows/test.yml
252-
[pypi_badge]: https://badge.fury.io/py/python-dotenv.svg
251+
[gh-bbc2]: https://github.com/bbc2
252+
[saurabh-homepage]: https://saurabh-kumar.com
253253
[pypi_link]: https://badge.fury.io/py/python-dotenv
254+
[pypi_badge]: https://badge.fury.io/py/python-dotenv.svg
254255
[python_streams]: https://docs.python.org/3/library/io.html
256+
[contributors]: https://github.com/theskumar/python-dotenv/graphs/contributors
257+
[build_status_link]: https://github.com/theskumar/python-dotenv/actions/workflows/test.yml
258+
[build_status_badge]: https://github.com/theskumar/python-dotenv/actions/workflows/test.yml/badge.svg

0 commit comments

Comments
 (0)