Skip to content

Commit 0a63a9e

Browse files
Update README.rst
1 parent 7c9b250 commit 0a63a9e

File tree

1 file changed

+44
-29
lines changed

1 file changed

+44
-29
lines changed

README.rst

Lines changed: 44 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
========================================================
12
Python Decouple: Strict separation of settings from code
23
========================================================
34

@@ -22,8 +23,6 @@ for separating settings from code.
2223
:target: https://pypi.python.org/pypi/python-decouple/
2324
:alt: Latest PyPI version
2425

25-
26-
2726
.. contents:: Summary
2827

2928

@@ -42,6 +41,7 @@ The first 2 are *project settings* and the last 3 are *instance settings*.
4241

4342
You should be able to change *instance settings* without redeploying your app.
4443

44+
4545
Why not just use environment variables?
4646
---------------------------------------
4747

@@ -61,8 +61,9 @@ Since it's a non-empty string, it will be evaluated as True.
6161

6262
*Decouple* provides a solution that doesn't look like a workaround: ``config('DEBUG', cast=bool)``.
6363

64+
6465
Usage
65-
=====
66+
======
6667

6768
Install:
6869

@@ -88,6 +89,7 @@ Then use it on your ``settings.py``.
8889
EMAIL_HOST = config('EMAIL_HOST', default='localhost')
8990
EMAIL_PORT = config('EMAIL_PORT', default=25, cast=int)
9091
92+
9193
Encodings
9294
---------
9395
Decouple's default encoding is `UTF-8`.
@@ -112,11 +114,13 @@ If you wish to fall back to your system's default encoding use:
112114
config.encoding = locale.getpreferredencoding(False)
113115
SECRET_KEY = config('SECRET_KEY')
114116
117+
115118
Where is the settings data stored?
116119
-----------------------------------
117120

118121
*Decouple* supports both *.ini* and *.env* files.
119122

123+
120124
Ini file
121125
~~~~~~~~
122126

@@ -134,6 +138,7 @@ Simply create a ``settings.ini`` next to your configuration module in the form:
134138
135139
*Note*: Since ``ConfigParser`` supports *string interpolation*, to represent the character ``%`` you need to escape it as ``%%``.
136140

141+
137142
Env file
138143
~~~~~~~~
139144

@@ -148,6 +153,7 @@ Simply create a ``.env`` text file in your repository's root directory in the fo
148153
PERCENTILE=90%
149154
#COMMENTED=42
150155
156+
151157
Example: How do I use it with Django?
152158
-------------------------------------
153159

@@ -191,6 +197,7 @@ and `dj-database-url <https://pypi.python.org/pypi/dj-database-url/>`_.
191197
192198
# ...
193199
200+
194201
Attention with *undefined* parameters
195202
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
196203

@@ -201,6 +208,7 @@ If ``SECRET_KEY`` is not present in the ``.env``, *decouple* will raise an ``Und
201208

202209
This *fail fast* policy helps you avoid chasing misbehaviours when you eventually forget a parameter.
203210

211+
204212
Overriding config files with environment variables
205213
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
206214

@@ -297,6 +305,7 @@ Let's see some examples for the above mentioned cases:
297305
298306
As you can see, ``cast`` is very flexible. But the last example got a bit complex.
299307

308+
300309
Built in Csv Helper
301310
~~~~~~~~~~~~~~~~~~~
302311

@@ -340,6 +349,7 @@ By default *Csv* returns a ``list``, but you can get a ``tuple`` or whatever you
340349
>>> config('SECURE_PROXY_SSL_HEADER', cast=Csv(post_process=tuple))
341350
('HTTP_X_FORWARDED_PROTO', 'https')
342351
352+
343353
Built in Choices helper
344354
~~~~~~~~~~~~~~~~~~~~~~~
345355

@@ -383,56 +393,61 @@ You can also use a Django-like choices tuple:
383393
>>> config('CONNECTION_TYPE', cast=Choices(choices=CONNECTION_OPTIONS))
384394
'bluetooth'
385395
396+
386397
Frequently Asked Questions
387398
==========================
388399

400+
389401
1) How to specify the `.env` path?
390402
----------------------------------
391403

392-
```python
393-
import os
394-
from decouple import Config, RepositoryEnv
395-
config = Config(RepositoryEnv("path/to/.env"))
396-
```
404+
.. code-block:: python
405+
406+
>>> import os
407+
>>> from decouple import Config, RepositoryEnv
408+
>>> config = Config(RepositoryEnv("path/to/.env"))
409+
397410
398411
2) How to use python-decouple with Jupyter?
399412
-------------------------------------------
400413

401-
```python
402-
import os
403-
from decouple import Config, RepositoryEnv
404-
config = Config(RepositoryEnv("path/to/.env"))
405-
```
414+
.. code-block:: python
415+
416+
>>> import os
417+
>>> from decouple import Config, RepositoryEnv
418+
>>> config = Config(RepositoryEnv("path/to/.env"))
419+
406420
407421
3) How to specify a file with another name instead of `.env`?
408422
----------------------------------------------------------------
409423

410-
```python
411-
import os
412-
from decouple import Config, RepositoryEnv
413-
config = Config(RepositoryEnv("path/to/somefile-like-env"))
414-
```
424+
.. code-block:: python
425+
426+
>>> import os
427+
>>> from decouple import Config, RepositoryEnv
428+
>>> config = Config(RepositoryEnv("path/to/somefile-like-env"))
429+
415430
416431
4) How to define the path to my env file on a env var?
417432
--------------------------------------------------------
418433

419-
```python
420-
import os
421-
from decouple import Config, RepositoryEnv
434+
.. code-block:: python
435+
436+
>>> import os
437+
>>> from decouple import Config, RepositoryEnv
438+
>>> DOTENV_FILE = os.environ.get("DOTENV_FILE", ".env") # only place using os.environ
439+
>>> config = Config(RepositoryEnv(DOTENV_FILE))
422440
423-
DOTENV_FILE = os.environ.get("DOTENV_FILE", ".env") # only place using os.environ
424-
config = Config(RepositoryEnv(DOTENV_FILE))
425-
```
426441
427442
5) How can I have multiple *env* files working together?
428443
--------------------------------------------------------
429444

430-
```python
431-
from collections import ChainMap
432-
from decouple import Config, RepositoryEnv
445+
.. code-block:: python
446+
447+
>>> from collections import ChainMap
448+
>>> from decouple import Config, RepositoryEnv
449+
>>> config = Config(ChainMap(RepositoryEnv(".private.env"), RepositoryEnv(".env")))
433450
434-
config = Config(ChainMap(RepositoryEnv(".private.env"), RepositoryEnv(".env")))
435-
```
436451
437452
Contribute
438453
==========

0 commit comments

Comments
 (0)