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. By default it will search for .env and .env.local files.

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.

Manual load

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

import readenv

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

Custom environment

You can create your own environment

import readenv

env = readenv.Environ()

or start with the current environ copy

import copy
import os
import readenv

env = Environ(copy.deepcopy(os.environ))

Examples

Django integration

Put the helper import as first place

manage.py

#!/usr/bin/env python3

import readenv.loads  # noqa: F401 isort:skip

import sys


if __name__ == "__main__":
    readenv.setdefault("DJANGO_SETTINGS_MODULE", "myproject.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
from django.core.wsgi import get_wsgi_application


readenv.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings")
application = get_wsgi_application()

asgi.py

import readenv.loads  # noqa: F401 isort:skip
from django.core.asgi import get_asgi_application


readenv.setdefault("DJANGO_SETTINGS_MODULE", "myproject.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.3.1.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.3.1-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: python-readenv-0.3.1.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.3.1.tar.gz
Algorithm Hash digest
SHA256 66181e3a4745777a10c14c72c6a08caa5d6c5cec550fd7a02b05858889f9bcd3
MD5 de2c55c6adb099b1f8b5e43290c08836
BLAKE2b-256 9d8fe8f08eba98480e85cdefb396a8f4a58fa9f293454f5884af86770361f521

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_readenv-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 8.9 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.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5b4129e379a16744aff6272c1bb61c13cb60f968f1b81d53354cdcaa2018620a
MD5 7688fd48a6def2597a0ebd4d9894df20
BLAKE2b-256 34bafe0c36b6ad9bc8acc59cd83aea8fcfbaf01253959e51aeea7430675ad5b2

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