Skip to main content

Read dotenv file

Project description

To read from .env file and put it into os.environ. This project is based on https://github.com/theskumar/python-dotenv

Install

$ pip install -e git+https://github.com/aongko/py_dotenv@master#egg=py_dotenv-0

Clone this project, run:

$ python3 setup.py install

Example

Assuming you have an .env file alongside your main module.

.
├── .env
└── main.py

The code would look like this:

import os
from py_dotenv import read_dotenv

dotenv_path = os.path.join(os.path.dirname(__file__), '.env')
read_dotenv(dotenv_path)

Let’s assume your .env file looks like this:

APP_DEBUG = TRUE
CUSTOM_CONFIGURATION = ABC

After running the code above, you now can access the environment variable like this:

assert os.getenv('APP_DEBUG') == 'TRUE'
assert os.getenv('CUSTOM_CONFIGURATION') == 'ABC'

Project details


Release history Release notifications

This version
History Node

0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
py_dotenv-0.1-py3-none-any.whl (3.6 kB) Copy SHA256 hash SHA256 Wheel py3 Dec 13, 2016

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page