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

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

  • Free software: MIT license

  • Documentation: https://runenv.readthedocs.org.

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.0.tar.gz (21.7 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.2.0-py2.py3-none-any.whl (7.2 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

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

File hashes

Hashes for runenv-1.2.0.tar.gz
Algorithm Hash digest
SHA256 53e3bc6414cfdcbf4a840762d352b413851ac9951db398f593c0abaa407365c6
MD5 c112831f0061fdcae4beddfaf45c6492
BLAKE2b-256 6785bc8bc33c72d7e64a9625bb61ffdf4ac9ab887d3b531cdcf2a32f7c04dc70

See more details on using hashes here.

File details

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

File metadata

  • Download URL: runenv-1.2.0-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.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 b8db6ad8ed45c3631c9ca19fef495bb5c8a7ee04310d592eb51e033d63ff5e42
MD5 9c410d5b011f36863f7efb78d8005438
BLAKE2b-256 1e7d9f95b0bb96c2b63e953fb50e83bc95de93b4333efc2e8de7a5a627f2e0d7

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