Skip to content

Commit 3d0359b

Browse files
author
Saurabh Kumar
committed
cleanup and make reamde more readable
1 parent c22475b commit 3d0359b

2 files changed

Lines changed: 55 additions & 29 deletions

File tree

File renamed without changes.

README.md

Lines changed: 55 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,84 @@
1+
<pre>
2+
_______ .__ __. ____ ____
3+
| ____|| \ | | \ \ / /
4+
| |__ | \| | \ \/ /
5+
| __| | . ` | \ /
6+
__ | |____ | |\ | \ /
7+
(__)|_______||__| \__| \__/
8+
</pre>
19
# python-dotenv
210

311
[![Build Status](https://travis-ci.org/theskumar/python-dotenv.svg?branch=master)](https://travis-ci.org/theskumar/python-dotenv) [![Coverage Status](https://coveralls.io/repos/theskumar/python-dotenv/badge.svg?branch=master)](https://coveralls.io/r/theskumar/python-dotenv?branch=master) [![PyPI version](https://badge.fury.io/py/python-dotenv.svg)](http://badge.fury.io/py/python-dotenv) [![PyPI](https://img.shields.io/pypi/dm/python-dotenv.svg)]()
412

5-
# Features
13+
Reads the key,value pair from `.env` and adds them to environment variable. It is great of managing app settings during development and in production using [12-factor] principles.
614

7-
The original work is based on [django-dotenv](https://github.com/jacobian/django-dotenv) by jacobian.
15+
> Do one thing, do it well!
816
9-
- read values from .env file and loads them as environment variable.
10-
- use it any python project not just django.
11-
- commandline interface to read/write `.env` file on your local and remote servers.
12-
- python 2 and 3 support
17+
<!-- MarkdownTOC -->
1318

19+
- [Usages](#usages)
20+
- [Installation](#installation)
21+
- [Command-line interface](#command-line-interface)
22+
- [Setting config on remote servers](#setting-config-on-remote-servers)
23+
- [Contributing](#contributing)
1424

15-
# Installation
25+
<!-- /MarkdownTOC -->
26+
27+
28+
[12-factor]: http://12factor.net/
29+
30+
# Usages
31+
32+
`.env` is a simple text file. With each environment variables listed per line, in the format of `KEY="Value"`
1633

34+
<pre>
35+
SECRET_KEY="your_secret_key"
36+
DATABASE_PASSWORD="your_database_password"
37+
...
38+
</pre>
39+
40+
Assuming you have created the `.env` file along-side your settings module.
1741
```
18-
pip install python-dotenv --upgrade
42+
.
43+
├── .env
44+
└── settings.py
1945
```
2046

21-
# Usage
47+
Add the following code to your `settings.py`
2248

23-
## Loading variables from a `.env` file into your python project
49+
```python
50+
# settings.py
51+
from os.path import join, dirname
52+
from dotenv import load_dotenv
2453

25-
### Any Python Project
54+
dotenv_path = join(dirname(__file__), '.env')
55+
load_dotenv(dotenv_path)
56+
```
2657

27-
Add the following line at the start of the file, from your program starts:
58+
Now, you can access the variables either from existing environment variable or loaded from `.env` file. `.env` file gets higher precedence, and it's adviced not to include it in version control.
2859

2960
```python
30-
import dotenv
31-
dotenv.load_dotenv("/path/to/.env")
61+
# settings.py
62+
63+
SECRET_KEY = os.environ.get("SECRET_KEY")
64+
DATABASE_PASSWORD = os.environ.get("DATABASE_PASSWORD")
3265
```
3366

3467
### Django
3568

36-
If you are using django you should add the above loader script at the top of `settings.py` and `manage.py`.
37-
38-
NOTE: If you use [django-configurations], support for reading `.env` file is coming soon[1]!
69+
If you are using django you should add the above loader script at the top of `wsgi.py` and `manage.py`.
3970

40-
[1] https://github.com/jezdez/django-configurations/commit/01e3f5837f3d0fed215d
41-
42-
[django-configurations]: https://github.com/jezdez/django-configurations
4371

72+
# Installation
4473

45-
## Format of `.env` file
74+
```
75+
pip install python-dotenv --upgrade
76+
```
4677

47-
`.env` is a simple text file. With each environment variables listed per line, in the format of `KEY="Value"`
4878

49-
<pre>
50-
SECRET_KEY="your_secret_key"
51-
DATABASE_PASSWORD="your_database_password"
52-
...
53-
</pre>
79+
# Command-line interface
5480

55-
## Command-line interface
81+
A cli interface `dotenv` is also included, which helps you manipulate the `.env` file without manually opening it. The same cli installed on remote machine combined with fabric (discussed later) will enable you to update your settings on remote server, handy isn't it!
5682

5783
<pre>
5884
$ dotenv
@@ -155,6 +181,6 @@ That's it. example.com, or whoever your non-paas host is, is now 1 facor closer
155181

156182
# Contributing
157183

158-
Please open [an issue] or send us a pull request.
184+
All the contributions are welcome! Please open [an issue] or send us a pull request.
159185

160186
[an issue]: https://github.com/theskumar/python-dotenv/issues/new

0 commit comments

Comments
 (0)