@@ -7,17 +7,7 @@ python-dotenv reads key-value pairs from a `.env` file and can set them as
77environment variables. It helps in the development of applications following the
88[ 12-factor] ( https://12factor.net/ ) principles.
99
10- - [ Getting Started] ( #getting-started )
11- - [ 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 )
15- - [ Command-line Interface] ( #command-line-interface )
16- - [ File format] ( #file-format )
17- - [ Multiline values] ( #multiline-values )
18- - [ Variable expansion] ( #variable-expansion )
19- - [ Related Projects] ( #related-projects )
20- - [ Acknowledgements] ( #acknowledgements )
10+ > ** [ Read the full documentation] ( https://theskumar.github.io/python-dotenv/ ) **
2111
2212## Getting Started
2313
@@ -73,163 +63,9 @@ like `${DOMAIN}`, as bare variables such as `$DOMAIN` are not expanded.
7363You will probably want to add ` .env ` to your ` .gitignore ` , especially if it
7464contains secrets like a password.
7565
76- See the section "[ File format] ( #file-format ) " below for more information about what you can write in a ` .env ` file.
77-
78- ## Other Use Cases
79-
80- ### Load configuration without altering the environment
81-
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-
86- ``` python
87- from dotenv import dotenv_values
88-
89- config = dotenv_values(" .env" ) # config = {"USER": "foo", "EMAIL": "foo@example.org"}
90- ```
91-
92- This notably enables advanced configuration management:
93-
94- ``` python
95- import os
96- from dotenv import dotenv_values
97-
98- config = {
99- ** dotenv_values(" .env.shared" ), # load shared development variables
100- ** dotenv_values(" .env.secret" ), # load sensitive variables
101- ** os.environ, # override loaded values with environment variables
102- }
103- ```
104-
105- ### Parse configuration as a stream
106-
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-
111- ``` python
112- from io import StringIO
113-
114- from dotenv import load_dotenv
115-
116- config = StringIO(" USER=foo\n EMAIL=foo@example.org" )
117- load_dotenv(stream = config)
118- ```
119-
120- ### Load .env files in IPython
121-
122- You can use dotenv in IPython. By default, it will use ` find_dotenv ` to search for a
123- ` .env ` file:
124-
125- ``` python
126- % load_ext dotenv
127- % dotenv
128- ```
129-
130- You can also specify a path:
131-
132- ``` python
133- % dotenv relative/ or / absolute/ path/ to/ .env
134- ```
135-
136- Optional flags:
137-
138- - ` -o ` to override existing variables.
139- - ` -v ` for increased verbosity.
140-
141- ### Disable load_dotenv
142-
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.
146-
147- ## Command-line Interface
148-
149- A CLI interface ` dotenv ` is also included, which helps you manipulate the ` .env `
150- file without manually opening it.
151-
152- ``` shell
153- $ pip install " python-dotenv[cli]"
154- $ dotenv set USER foo
155- $ dotenv set EMAIL foo@example.org
156- $ dotenv list
157- USER=foo
158- EMAIL=foo@example.org
159- $ dotenv list --format=json
160- {
161- " USER" : " foo" ,
162- " EMAIL" : " foo@example.org"
163- }
164- $ dotenv run -- python foo.py
165- ```
166-
167- Run ` dotenv --help ` for more information about the options and subcommands.
168-
169- ## File format
170-
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.
174-
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.
179-
180- Allowed escape sequences:
181-
182- - in single-quoted values: ` \\ ` , ` \' `
183- - in double-quoted values: ` \\ ` , ` \' ` , ` \" ` , ` \a ` , ` \b ` , ` \f ` , ` \n ` , ` \r ` , ` \t ` , ` \v `
184-
185- ### Multiline values
186-
187- It is possible for single- or double-quoted values to span multiple lines. The
188- following examples are equivalent:
189-
190- ``` bash
191- FOO=" first line
192- second line"
193- ```
194-
195- ``` bash
196- FOO=" first line\nsecond line"
197- ```
198-
199- ### Variable without a value
200-
201- A variable can have no value:
202-
203- ``` bash
204- FOO
205- ```
206-
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.
210-
211- This shouldn't be confused with ` FOO= ` , in which case the variable is associated
212- with the empty string.
213-
214- ### Variable expansion
215-
216- python-dotenv can interpolate variables using POSIX variable expansion.
217-
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:
220-
221- - Value of that variable in the ` .env ` file.
222- - Value of that variable in the environment.
223- - Default value, if provided.
224- - Empty string.
225-
226- With ` load_dotenv(override=False) ` , the value of a variable is the first of the
227- values defined in the following list:
228-
229- - Value of that variable in the environment.
230- - Value of that variable in the ` .env ` file.
231- - Default value, if provided.
232- - Empty string.
66+ See the [ file format specification] ( https://theskumar.github.io/python-dotenv/reference/file-format/ )
67+ for full details on ` .env ` syntax, multiline values, escape sequences, and
68+ variable expansion.
23369
23470## Related Projects
23571
0 commit comments