You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
53
53
54
54
```
55
55
.
56
56
├── .env
57
57
└── foo.py
58
58
```
59
59
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:
61
62
62
63
```bash
63
64
# Development settings
@@ -66,22 +67,21 @@ ADMIN_EMAIL=admin@${DOMAIN}
66
67
ROOT_URL=${DOMAIN}/app
67
68
```
68
69
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.
71
72
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.
74
75
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.
77
77
78
78
## Other Use Cases
79
79
80
80
### Load configuration without altering the environment
81
81
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.
85
85
86
86
```python
87
87
from dotenv import dotenv_values
@@ -104,9 +104,9 @@ config = {
104
104
105
105
### Parse configuration as a stream
106
106
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).
110
110
111
111
```python
112
112
from io import StringIO
@@ -119,7 +119,7 @@ load_dotenv(stream=config)
119
119
120
120
### Load .env files in IPython
121
121
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
123
123
`.env` file:
124
124
125
125
```python
@@ -140,12 +140,14 @@ Optional flags:
140
140
141
141
### Disable load_dotenv
142
142
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.
144
146
145
147
## Command-line Interface
146
148
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.
149
151
150
152
```shell
151
153
$ pip install "python-dotenv[cli]"
@@ -166,13 +168,14 @@ Run `dotenv --help` for more information about the options and subcommands.
166
168
167
169
## File format
168
170
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
173
+
pipes) on Unix systems is also supported.
171
174
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.
175
+
Keys can be unquoted or single-quoted. Values can be unquoted, single- or
176
+
double-quoted. Spaces before and after keys, equal signs, and values are
177
+
ignored. Values can be followed by a comment. Lines can start with the `export`
178
+
directive, which does not affect their interpretation.
176
179
177
180
Allowed escape sequences:
178
181
@@ -181,8 +184,8 @@ Allowed escape sequences:
181
184
182
185
### Multiline values
183
186
184
-
It is possible for single- or double-quoted values to span multiple lines. The following
185
-
examples are equivalent:
187
+
It is possible for single- or double-quoted values to span multiple lines. The
188
+
following examples are equivalent:
186
189
187
190
```bash
188
191
FOO="first line
@@ -201,26 +204,27 @@ A variable can have no value:
201
204
FOO
202
205
```
203
206
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.
207
+
It results in `dotenv_values` associating that variable name with the value
208
+
`None` (e.g. `{"FOO": None}`. `load_dotenv`, on the other hand, simply ignores
209
+
such variables.
206
210
207
-
This shouldn't be confused with `FOO=`, in which case the variable is associated with the
208
-
empty string.
211
+
This shouldn't be confused with `FOO=`, in which case the variable is associated
212
+
with the empty string.
209
213
210
214
### Variable expansion
211
215
212
216
python-dotenv can interpolate variables using POSIX variable expansion.
213
217
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:
218
+
With `load_dotenv(override=True)` or `dotenv_values()`, the value of a variable
219
+
is the first of the values defined in the following list:
216
220
217
221
- Value of that variable in the `.env` file.
218
222
- Value of that variable in the environment.
219
223
- Default value, if provided.
220
224
- Empty string.
221
225
222
-
With `load_dotenv(override=False)`, the value of a variable is the first of the values
223
-
defined in the following list:
226
+
With `load_dotenv(override=False)`, the value of a variable is the first of the
227
+
values defined in the following list:
224
228
225
229
- Value of that variable in the environment.
226
230
- Value of that variable in the `.env` file.
@@ -229,27 +233,27 @@ defined in the following list:
229
233
230
234
## Related Projects
231
235
232
-
-[Honcho](https://github.com/nickstenning/honcho) - For managing
0 commit comments