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.2.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_readenv-0.2-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

Details for the file python-readenv-0.2.tar.gz.

File metadata

  • Download URL: python-readenv-0.2.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for python-readenv-0.2.tar.gz
Algorithm Hash digest
SHA256 c2c62aa3833008fa4ba8fbf2b1c8161aa3de3a319482ffc9ea8235e8c7ed76d8
MD5 8c19a07247dd5d45c13a8f02aa5b976a
BLAKE2b-256 e8e7bf82b8dd9385f9f85de448a93556a99b88ff13535b638638f9c38b90fe23

See more details on using hashes here.

File details

Details for the file python_readenv-0.2-py3-none-any.whl.

File metadata

  • Download URL: python_readenv-0.2-py3-none-any.whl
  • Upload date:
  • Size: 12.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for python_readenv-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9e90fce7ae33d72d8f1742f29c20f28522f7d29d79ba5a8fcaa2fbc091bb1494
MD5 bc30848c625a41427c6b97721f15e6a0
BLAKE2b-256 010d9aff12c28ce0bc7608832e00ae157efd142b4dbe1b95e9c371d6c3aae4b6

See more details on using hashes here.

Supported by

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