Skip to main content

Wrapper to run programs with different env

Project description

https://img.shields.io/travis/onjin/runenv.svg https://img.shields.io/pypi/v/runenv.svg https://img.shields.io/badge/license-New%20BSD-blue.svg https://img.shields.io/pypi/dm/runenv.svg

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

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)

Loads environment from given env_file`, default .env.

If prefix provided only variables started with given prefix will be loaded to environment with keys truncated from prefix. To preserver prefix, pass strip_prefix=False.

Example:

$ echo 'DJANGO_SECRET_KEY=bzemAG0xfdMgFrHBT3tJBbiYIoY6EeAj' > .env

$ python
>>> import os
>>> from runenv import load_env
>>> load_env(prefix='DJANGO_')
>>> 'DJANGO_SECRET_KEY' in os.environ
False
>>> 'SECRET_KEY' in os.environ
True
>>> load_env(prefix='DJANGO_', strip_prefix=False)
>>> 'DJANGO_SECRET_KEY' in os.environ
True

Notice: Environment will not be loaded if command was fired by runenv wrapper until you use force=True parameter

Wrapper runenv sets _RUNENV_WRAPPED=1 variable and load_env does not load variables then.

Example:

$ echo 'DJANGO_SECRET_KEY=bzemAG0xfdMgFrHBT3tJBbiYIoY6EeAj' > .env

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

Django integration

To use load_env with Django, put in manage.py and wsgi.py code:

from runenv import load_env
load_env()

Similar projects

History

0.2.2 (2015-06-16)

  • fix compatibility with python3

0.2.1 (2015-06-16)

  • add strip_prefix option to load_env

0.2.0 (2015-06-16)

  • add load_env (python api)

0.1.4 (2015-06-15)

  • Check if file to run exists and is executable

0.1.3 (2015-06-01)

  • Support for env file comments by ‘#’

0.1.2 (2015-06-01)

  • Return code from runned command

0.1.1 (2015-05-31)

  • First release on PyPI.

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

Uploaded Source

Built Distribution

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

runenv-0.2.2-py2.py3-none-any.whl (6.2 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

  • Download URL: runenv-0.2.2.tar.gz
  • Upload date:
  • Size: 14.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for runenv-0.2.2.tar.gz
Algorithm Hash digest
SHA256 7ffa557a16299532b5c970f1d251ac7334ede8f025e00ab4f9c466b94e5e7ee1
MD5 8917ba8f2e76f73dc6c890f61d40d3cc
BLAKE2b-256 70e099d5ccd2f22a2fe8d371530daf985241cb59c1fd45afe8a9aa678532e6c3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for runenv-0.2.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 a43ffb910b26076a479697a5e5be556775a4574d7e4a297184e5354be541f272
MD5 f05f9a5ce3167eedb4d10f71f49415d9
BLAKE2b-256 a27e861116f091cdda2582b62fdda1ae42d83700466a2d4b56501f24ea3661f7

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