Skip to main content

No project description provided

Project description

runenv

CI/CD CI - Test
Package PyPI - Version PyPI - Downloads PyPI - Python Version
Meta linting - Ruff code style - Black types - Mypy License - MIT
Changes CHANGELOG.md

You can use runenv to manage your app settings using 12-factor principles.

The runenv package provides a few things:

  • [cli] Wrapper to run programs with modified environment variables loaded from given .env file.
  • [api] Python API to load variables from .env file into environment

Table of Contents

Installation

To install runenv package along with runenv CLI command run:

pip install runenv

Usage

Fist you have to create .env (this is the default name, you can use any name and have multiple environment files in projects) file in your project.

Example .env file:

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

# line with comment
EMAIL_HOST=smtp.mandrillapp.com
EMAIL_PORT=587                             # inline comment
EMAIL_HOST_USER="double quoted value"
EMAIL_HOST_PASSWORD='single quoted value'
EMAIL_FROM=user@${EMAIL_HOST}              # reuse variable from same file
EMAIL_USE_TLS=1

Python API

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

This function is loading content of .env file into environment without raising errors if file does not exist.

Options:

  • env_file: optional environment file name; default .env
  • prefix: optional prefix to filter loaded variables; f.e. DJANGO_ will load only DJANGO_* variables
  • strip_prefix: whether strip prefix when loading variables; default True; f.e. DJANGO_SECRET will be loaded as SECRET if prefix=DJANGO_
  • force: whether load .env file again, even if application was started by runenv CLI wrapper (this wrapper already is loading .env file)
  • search_parent: how many parent directories search for .env file; default 0

create_env(env_file=".env", prefix=None, strip_prefix=True)`

This function is only parsing content of .env file and returns it as python dictionary, without changing environment.

Options:

  • env_file: optional environment file name; default .env
  • prefix: optional prefix to filter loaded variables; f.e. DJANGO_ will load only DJANGO_* variables
  • strip_prefix: whether strip prefix when loading variables; default True; f.e. DJANGO_SECRET will be loaded as SECRET if prefix=DJANGO_

CLI

The runenv CLI can be used to run commands wrapped with environment loaded from passed .env files.

$ runenv --help
usage: runenv [-h] [-V] [-v {1,2,3}] [-p PREFIX] [-s] [--dry_run] env_file command

Run program with given environment file loaded

positional arguments:
  env_file              Environment file to load
  command               Command to run with loaded environment

options:
  -h, --help            show this help message and exit
  -V, --version         show program's version number and exit
  -v {1,2,3}, --verbosity {1,2,3}
                        verbosity level, 1 - (ERROR, default), 2 - (INFO) or 3 - (DEBUG)
  -p PREFIX, --prefix PREFIX
                        Load only variables with given prefix
  -s, --strip_prefix    Strip prefix given with --prefix from environment variables names
  --dry_run             Return parsed .env instead of running command

Example usage:

Run ./manage.py serve command with environment loaded from .env.development file.

$ runenv .env.development ./manage.py serve

Options:

  • env_file: environment file name to load
  • --prefix: optional prefix to filter loaded variables; f.e. DJANGO_ will load only DJANGO_* variables
  • --strip-prefix: whether strip prefix when loading variables; default True; f.e. DJANGO_SECRET will be loaded as SECRET if prefix=DJANGO_
  • --dry-run: only display parsed .env result instead of loading environment and running command

Integration

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

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

Uploaded Source

Built Distribution

runenv-1.2.2-py2.py3-none-any.whl (7.2 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

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

File hashes

Hashes for runenv-1.2.2.tar.gz
Algorithm Hash digest
SHA256 e05fa2da610625d0d537f464a9b24e4c66896acfb772c3a7e28331d299e77640
MD5 2a963334dc95194d9909d84149efd83f
BLAKE2b-256 b7e3b90e1608f76c05666d7adee568f2e08da23317c302ec297d79393edf78b7

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for runenv-1.2.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 f3e36aa4e25bb054c4200d915be1b5faf3096f7791865b5be42feb9f056b2ff1
MD5 babf6a4541539dec6076d18109e1fb64
BLAKE2b-256 a151c52e100777237e824f2474a22672ce72d9be8cbc6d0979103fcc3a191636

See more details on using hashes here.

Supported by

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