dotenv
dotenv_values
dotenv_values(dotenv_path=None, stream=None, verbose=False, interpolate=True, encoding='utf-8')
Parse a .env file and return its content as a dict.
The returned dict will have None
values for keys without values in the .env file.
For example, foo=bar
results in {"foo": "bar"}
whereas foo
alone results in
{"foo": None}
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dotenv_path |
Optional[StrPath]
|
Absolute or relative path to the .env file. |
None
|
stream |
Optional[IO[str]]
|
|
None
|
verbose |
bool
|
Whether to output a warning if the .env file is missing. |
False
|
encoding |
Optional[str]
|
Encoding to be used to read the file. |
'utf-8'
|
If both dotenv_path
and stream
are None
, find_dotenv()
is used to find the
.env file.
Source code in dotenv/main.py
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 |
|
find_dotenv
find_dotenv(filename='.env', raise_error_if_not_found=False, usecwd=False)
Search in increasingly higher folders for the given file
Returns path to the file if found, or an empty string otherwise
Source code in dotenv/main.py
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 |
|
get_cli_string
get_cli_string(path=None, action=None, key=None, value=None, quote=None)
Returns a string suitable for running as a shell script.
Useful for converting a arguments passed to a fabric task
to be passed to a local
or run
command.
Source code in dotenv/__init__.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
|
get_key
get_key(dotenv_path, key_to_get, encoding='utf-8')
Get the value of a given key from the given .env.
Returns None
if the key isn't found or doesn't have a value.
Source code in dotenv/main.py
116 117 118 119 120 121 122 123 124 125 126 |
|
load_dotenv
load_dotenv(dotenv_path=None, stream=None, verbose=False, override=False, interpolate=True, encoding='utf-8')
Parse a .env file and then load all the variables found as environment variables.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dotenv_path |
Optional[StrPath]
|
Absolute or relative path to .env file. |
None
|
stream |
Optional[IO[str]]
|
Text stream (such as |
None
|
verbose |
bool
|
Whether to output a warning the .env file is missing. |
False
|
override |
bool
|
Whether to override the system environment variables with the variables
from the |
False
|
encoding |
Optional[str]
|
Encoding to be used to read the file. |
'utf-8'
|
Returns:
Name | Type | Description |
---|---|---|
Bool |
bool
|
True if at least one environment variable is set else False |
If both dotenv_path
and stream
are None
, find_dotenv()
is used to find the
.env file.
Source code in dotenv/main.py
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 |
|
set_key
set_key(dotenv_path, key_to_set, value_to_set, quote_mode='always', export=False, encoding='utf-8')
Adds or Updates a key/value to the given .env
If the .env path given doesn't exist, fails instead of risking creating an orphan .env somewhere in the filesystem
Source code in dotenv/main.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
|
unset_key
unset_key(dotenv_path, key_to_unset, quote_mode='always', encoding='utf-8')
Removes a given key from the given .env
file.
If the .env path given doesn't exist, fails. If the given key doesn't exist in the .env, fails.
Source code in dotenv/main.py
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
|