Skip to main content

No project description provided

Project description

runenv

image

image

image

image

image

Wrapper to run programs with modified environment variables loaded from given file. You can use runenv to manage your app settings using 12-factor principles.

You can use same environment file with runenv and with docker using env-file parameter

Features

CLI:

  • command-line tool to load environment variables from given file

Python API:

  • load variables from a file (.env or passed filename)
  • load only variables with given prefix
  • prefix can be stripped during load
  • detect whether environment was loaded by runenv CLI
  • force load even if runenv CLI was used
  • search_parent option which allows to look for env_file in parent dirs

Installation

In order to install use pip

$ pip install -U runenv

Usage

Run from shell

$ runenv env.development ./manage.py runserver

example env.development file

BASE_URL=http://127.0.0.1:8000
DATABASE_URI=postgres://postgres:password@localhost/dbname
SECRET_KEY=y7W8pbRcuPuAmgTHsJtEpKocb7XPcV0u

# email settings
EMAIL_HOST=smtp.mandrillapp.com
EMAIL_PORT=587
EMAIL_HOST_USER=someuser
EMAIL_HOST_PASSWORD=hardpassword
EMAIL_FROM=dev@local.host
EMAIL_USE_TLS=1

Python API

load_env(env_file='.env', prefix=None, strip_prefix=True, force=False, search_parent=0)

Loads environment from given env_file(default.env`).

Options:


option default description


env_file .env relative or absolute path to file with environment variables

prefix None prefix to match variables e.g. APP_

str True should the prefix be stripped during loa ip_prefix

force False load env_file, even though runenv CLI command was used

sear 0 To what level traverse parents in search ch_parent of file

If prefix option is provided only variables starting with it will be loaded to environment, with their keys stripped of that prefix. To preserve prefix, you can set strip_prefix to False.

Example

$ echo 'APP_SECRET_KEY=bzemAG0xfdMgFrHBT3tJBbiYIoY6EeAj' > .env
$ python
>>> import os
>>> from runenv import load_env
>>> load_env(prefix='APP_')
>>> 'APP_SECRET_KEY' in os.environ
False
>>> 'SECRET_KEY' in os.environ
True
>>> load_env(prefix='APP_', strip_prefix=False)
>>> 'APP_SECRET_KEY' in os.environ
True

Notice: Environment will not be loaded if command was fired by runenv wrapper, unless you set the force parameter to True

load_env does not load variables when wrapper runenv is used. Also _RUNENV_WRAPPED is set to 1

Example

$ echo 'APP_SECRET_KEY=bzemAG0xfdMgFrHBT3tJBbiYIoY6EeAj' > .env
$ python
>>> import os
>>> from runenv import load_env
>>> os.environ['_RUNENV_WRAPPED'] = '1'
>>> load_env()
>>> 'APP_SECRET_KEY' in os.environ
False
>>> load_env(force=True)
>>> 'APP_SECRET_KEY' in os.environ
True

Django/Flask integration

To use load_env with Django or Flask, put the followin in manage.py and wsgi.py

from runenv import load_env
load_env()

Similar projects

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

runenv-1.1.1.tar.gz (33.8 kB view details)

Uploaded Source

Built Distribution

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

runenv-1.1.1-py2.py3-none-any.whl (5.8 kB view details)

Uploaded Python 2Python 3

File details

Details for the file runenv-1.1.1.tar.gz.

File metadata

  • Download URL: runenv-1.1.1.tar.gz
  • Upload date:
  • Size: 33.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.27.2

File hashes

Hashes for runenv-1.1.1.tar.gz
Algorithm Hash digest
SHA256 70704fc6248162c76460f33bcc1b56ae133dd9e1974e782b45e9e9cf9a6fcc6f
MD5 0fddcca096d91a3842d1f51efe0ef57f
BLAKE2b-256 f6873e411e4d94e85fc31c0b80b6e761e5c07c775c50ec447179053490d93910

See more details on using hashes here.

File details

Details for the file runenv-1.1.1-py2.py3-none-any.whl.

File metadata

  • Download URL: runenv-1.1.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.27.2

File hashes

Hashes for runenv-1.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 b5f79b9033ed1175828fbab67a689c0ad044662cb6126e8b7a752d5af421f4a5
MD5 99e31d7374155b23a3e4e3aa5d4fd91a
BLAKE2b-256 aa4521abc6cc6f5760dc37212f51c8778ec05882789f2dacc838628dfd1bd47b

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