<commit_before># django-dotenv-rw

[![Build Status](https://travis-ci.org/theskumar/django-dotenv-rw.svg?branch=master)](https://travis-ci.org/theskumar/django-dotenv-rw)

Forked from awesome but simpler [django-dotenv](https://github.com/jacobian/django-dotenv).  Removes black magic, makes loading .env in settings.py easier, adds remote .env file management capabilities.  Works as a drop-in replacement for django-dotenv.

[foreman](https://github.com/ddollar/foreman) reads from `.env`. `manage.py`
doesn't. Let's fix that.

[heroku config](https://devcenter.heroku.com/articles/config-vars) Lets you add/delete env variables on your remote server from your local command line.  django-dotenv-rw  when used with fabric lets you do the same ```heroku config:set DJANGO_ENV="PRODUCTION" ``` becomes ```fab config:set,DJANGO_ENV,PRODUCTION```

## Installation

```
pip install git+ssh://git@github.com/theskumar/django-dotenv-rw.git
```

## Usage: loading settings from a .env file into your django environment

Option 1 (suggested):  Near the top of `settings.py`. Add:

```
import os
import dotenv
PROJECT_PATH = os.path.dirname(os.path.dirname(__file__))
dotenv.load_dotenv(os.path.join(PROJECT_PATH, ".env"))
```

Option 2: If you want your server to set the env variables and only use `dotenv` when you're using `manage.py`: in `manage.py` add:
```
import dotenv
dotenv.load_dotenv(os.path.join(os.path.dirname(__file__), ".env"))
```


## Usage: setting remote config

This is a first pass, will likely change.

Add a config task to your local fabfile, `dotenv_path` is the location of the absolute path of '.env' on the remote server.
```
from fabric.api import task, local, env<commit_msg>style(readme): add toc and update heading<commit_after># django-dotenv-rw

[![Build Status](https://travis-ci.org/theskumar/django-dotenv-rw.svg?branch=master)](https://travis-ci.org/theskumar/django-dotenv-rw)

Forked from awesome but simpler [django-dotenv](https://github.com/jacobian/django-dotenv).  Removes black magic, makes loading .env in settings.py easier, adds remote .env file management capabilities.  Works as a drop-in replacement for django-dotenv.

[foreman](https://github.com/ddollar/foreman) reads from `.env`. `manage.py`
doesn't. Let's fix that.

[heroku config](https://devcenter.heroku.com/articles/config-vars) Lets you add/delete env variables on your remote server from your local command line.  django-dotenv-rw  when used with fabric lets you do the same ```heroku config:set DJANGO_ENV="PRODUCTION" ``` becomes ```fab config:set,DJANGO_ENV,PRODUCTION```

<!-- MarkdownTOC -->

- [Installation](#installation)
- [Usage](#usage)
    - [Loading settings from a `.env` file into your django environment](#loading-settings-from-a-.env-file-into-your-django-environment)
    - [Setting remote config](#setting-remote-config)

<!-- /MarkdownTOC -->


## Installation

```
pip install git+ssh://git@github.com/theskumar/django-dotenv-rw.git
```

# Usage

## Loading settings from a `.env` file into your django environment

Option 1 (suggested):  Near the top of `settings.py`. Add:

```
import os
import dotenv
PROJECT_PATH = os.path.dirname(os.path.dirname(__file__))
dotenv.load_dotenv(os.path.join(PROJECT_PATH, ".env"))
```

Option 2: If you want your server to set the env variables and only use `dotenv` when you're using `manage.py`: in `manage.py` add:
```
import dotenv
dotenv.load_dotenv(os.path.join(os.path.dirname(__file__), ".env"))
```

## Setting remote config

This is a first pass, will likely change.

Add a config task to your local fabfile, `dotenv_path` is the location of the absolute path of '.env' on the remote server.
```
from fabric.api import task, local, env
{'fraction_non_alphanumeric': 0.13527351118296954, 'fraction_numerical': 0.0010778765831312314, 'mean_word_length': 4.755038759689922, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 10, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1476103', 'n_tokens_mistral': 1233, 'n_tokens_neox': 1172, 'n_words': 364}