Skip to content
Prev Previous commit
Next Next commit
Docs on parse_dotenv(stream=...)
  • Loading branch information
alanjds committed Jan 15, 2018
commit 4c52dc125ee4f6a22da70d5d5dd4cc52ad6738a5
28 changes: 28 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,34 @@ Django
If you are using django you should add the above loader script at the
top of ``wsgi.py`` and ``manage.py``.


In-memory filelikes
-------------------

Is possible to not rely on the filesystem to parse filelikes from other sources
(e.g. from a network storage). ``parse_dotenv`` accepts a filelike `stream`.
Just be sure to rewind it before passing.

.. code:: python

from io import BytesIO
from dotenv.main import parse_dotenv
filelike = BytesIO('SPAM=EGSS\n')
filelike.seek(0)
parsed = parse_dotenv(stream=filelike)

The returned lazy generator yields ``(key,value)`` tuples.
To ease the consumption, is suggested to unpack it into a dictionary.

.. code:: python

os_env_like = dict(iter(parsed))
assert os_env_like['SPAM'] == 'EGGS'

This could be useful if you need to *consume* the envfile but not *apply* it
directly into the system environment.


Installation
============

Expand Down