Skip to content

Commit 2d17af6

Browse files
authored
Merge branch 'HBNetwork:master' into repository-string
2 parents d785d9d + 0573e6f commit 2d17af6

File tree

1 file changed

+55
-29
lines changed

1 file changed

+55
-29
lines changed

README.rst

Lines changed: 55 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,6 +61,7 @@ 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
6566
=====
6667

@@ -88,8 +89,10 @@ 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
---------
95+
9396
Decouple's default encoding is `UTF-8`.
9497

9598
But you can specify your preferred encoding.
@@ -112,11 +115,13 @@ If you wish to fall back to your system's default encoding use:
112115
config.encoding = locale.getpreferredencoding(False)
113116
SECRET_KEY = config('SECRET_KEY')
114117
118+
115119
Where is the settings data stored?
116-
-----------------------------------
120+
----------------------------------
117121

118122
*Decouple* supports both *.ini* and *.env* files.
119123

124+
120125
Ini file
121126
~~~~~~~~
122127

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

142+
137143
Env file
138144
~~~~~~~~
139145

@@ -148,6 +154,7 @@ Simply create a ``.env`` text file in your repository's root directory in the fo
148154
PERCENTILE=90%
149155
#COMMENTED=42
150156
157+
151158
Example: How do I use it with Django?
152159
-------------------------------------
153160

@@ -191,6 +198,7 @@ and `dj-database-url <https://pypi.python.org/pypi/dj-database-url/>`_.
191198
192199
# ...
193200
201+
194202
Attention with *undefined* parameters
195203
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
196204

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

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

212+
204213
Overriding config files with environment variables
205214
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
206215

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

309+
300310
Built in Csv Helper
301311
~~~~~~~~~~~~~~~~~~~
302312

@@ -340,6 +350,7 @@ By default *Csv* returns a ``list``, but you can get a ``tuple`` or whatever you
340350
>>> config('SECURE_PROXY_SSL_HEADER', cast=Csv(post_process=tuple))
341351
('HTTP_X_FORWARDED_PROTO', 'https')
342352
353+
343354
Built in Choices helper
344355
~~~~~~~~~~~~~~~~~~~~~~~
345356

@@ -383,56 +394,71 @@ You can also use a Django-like choices tuple:
383394
>>> config('CONNECTION_TYPE', cast=Choices(choices=CONNECTION_OPTIONS))
384395
'bluetooth'
385396
397+
386398
Frequently Asked Questions
387399
==========================
388400

401+
389402
1) How to specify the `.env` path?
390403
----------------------------------
391404

392-
```python
393-
import os
394-
from decouple import Config, RepositoryEnv
395-
config = Config(RepositoryEnv("path/to/.env"))
396-
```
405+
.. code-block:: python
406+
407+
import os
408+
from decouple import Config, RepositoryEnv
409+
410+
411+
config = Config(RepositoryEnv("path/to/.env"))
412+
397413
398414
2) How to use python-decouple with Jupyter?
399415
-------------------------------------------
400416

401-
```python
402-
import os
403-
from decouple import Config, RepositoryEnv
404-
config = Config(RepositoryEnv("path/to/.env"))
405-
```
417+
.. code-block:: python
418+
419+
import os
420+
from decouple import Config, RepositoryEnv
421+
422+
423+
config = Config(RepositoryEnv("path/to/.env"))
424+
406425
407426
3) How to specify a file with another name instead of `.env`?
408427
----------------------------------------------------------------
409428

410-
```python
411-
import os
412-
from decouple import Config, RepositoryEnv
413-
config = Config(RepositoryEnv("path/to/somefile-like-env"))
414-
```
429+
.. code-block:: python
430+
431+
import os
432+
from decouple import Config, RepositoryEnv
433+
434+
435+
config = Config(RepositoryEnv("path/to/somefile-like-env"))
436+
415437
416438
4) How to define the path to my env file on a env var?
417439
--------------------------------------------------------
418440

419-
```python
420-
import os
421-
from decouple import Config, RepositoryEnv
441+
.. code-block:: python
442+
443+
import os
444+
from decouple import Config, RepositoryEnv
445+
446+
447+
DOTENV_FILE = os.environ.get("DOTENV_FILE", ".env") # only place using os.environ
448+
config = Config(RepositoryEnv(DOTENV_FILE))
422449
423-
DOTENV_FILE = os.environ.get("DOTENV_FILE", ".env") # only place using os.environ
424-
config = Config(RepositoryEnv(DOTENV_FILE))
425-
```
426450
427451
5) How can I have multiple *env* files working together?
428452
--------------------------------------------------------
429453

430-
```python
431-
from collections import ChainMap
432-
from decouple import Config, RepositoryEnv
454+
.. code-block:: python
455+
456+
from collections import ChainMap
457+
from decouple import Config, RepositoryEnv
458+
459+
460+
config = Config(ChainMap(RepositoryEnv(".private.env"), RepositoryEnv(".env")))
433461
434-
config = Config(ChainMap(RepositoryEnv(".private.env"), RepositoryEnv(".env")))
435-
```
436462
437463
Contribute
438464
==========

0 commit comments

Comments
 (0)