Skip to main content

Wrapper to run programs with different env

Project description

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



  • 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


In order to install use pip

$ pip install -U runenv


Run from shell

$ runenv env.development ./ runserver

example env.development file


# email settings

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).


option default description
env_file .env relative or absolute path to file with environment variables
prefix None prefix to match variables e.g. APP_
strip_prefix True should the prefix be stripped during loa
force False load env_file, even though runenv CLI command was used
search_parent 0 To what level traverse parents in search 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.


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

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


$ 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
>>> load_env(force=True)
>>> 'APP_SECRET_KEY' in os.environ

Django/Flask integration

To use load_env with Django or Flask, put the followin in and

from runenv import load_env

Similar projects


1.0.1 (2017-02-03)

  • fix package description syntax

1.0.0 (2017-02-03)

  • changed version to 1.0.0

0.4.0 (2016-08-08)

  • add support for search_parent option

0.3.1 (2016-06-21)

  • add support for quoted values

0.3.0 (2016-02-14)

  • change Development Status to 5 - Production/Stable

0.2.5 (2015-11-30)

  • do not look for executable as absolute path

0.2.4 (2015-07-06)

  • skip load_env if env file does not exists

0.2.3 (2015-06-26)

  • support to run programs from PATH

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.

Files for runenv, version 1.0.1
Filename, size File type Python version Upload date Hashes
Filename, size runenv-1.0.1-py2.py3-none-any.whl (7.9 kB) File type Wheel Python version 2.7 Upload date Hashes View
Filename, size runenv-1.0.1.tar.gz (18.2 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page