Skip to main content

read an env file and export to os.environ

Project description

python-readenv

readenv makes it easy to automatically load environment variables from .env file(s) and put into os.environ.

Install

$ pip install python-readenv

Getting started

You can automatically load at startup time with the helper import import readenv.loads, which try to locate and load the first env file found from your current working directory up to root. readenv.readenv.loads will search for .env and .env.local files by default.

Automatic load

You can automatically load at startup time with the helper import

import readenv.loads

...

which try to locate and load the first env file found from your current working directory up to root.

Manually load

Alternatively, you can customize which files readenv should search and load

from readenv import readenv

readenv.loads("myenv", "myenv.local")

Examples

Django integration

Put the helper import as first place

manage.py

#!/usr/bin/env python3

import readenv.loads # noqa: F401 isort:skip

import os
import sys

if  __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")
    from django.core.management import execute_from_command_line
    execute_from_command_line(sys.argv)

wsgi.py

import readenv.loads # noqa: F401 isort:skip

import os
from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")
application = get_wsgi_application()

asgi.py

import readenv.loads # noqa: F401 isort:skip

import os
from django.core.asgi import get_asgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")
application = get_asgi_application()

Project details


Download files

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

Source Distribution

python-readenv-0.1.1.tar.gz (5.7 kB view hashes)

Uploaded Source

Built Distribution

python_readenv-0.1.1-py3-none-any.whl (7.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page