Skip to main content
Python Software Foundation 20th Year Anniversary Fundraiser  Donate today!

Read dotenv file

Project description

To read from .env file and put it into os.environ. This project is based on


$ pip install -e git+

Clone this project, run:

$ python3 install


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

├── .env

The code would look like this:

import os
from py_dotenv import read_dotenv

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

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


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 | RSS feed

This version


Download files

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

Files for py-dotenv, version 0.1
Filename, size File type Python version Upload date Hashes
Filename, size py_dotenv-0.1-py3-none-any.whl (3.6 kB) File type Wheel Python version py3 Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page