No project description provided
Project description
runenv
| CI/CD | |
| Package | |
| Meta | |
| 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.envprefix: optional prefix to filter loaded variables; f.e.DJANGO_will load onlyDJANGO_*variablesstrip_prefix: whether strip prefix when loading variables; defaultTrue; f.e.DJANGO_SECRETwill be loaded asSECRETifprefix=DJANGO_force: whether load.envfile again, even if application was started byrunenvCLI wrapper (this wrapper already is loading.envfile)search_parent: how many parent directories search for.envfile; default0
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.envprefix: optional prefix to filter loaded variables; f.e.DJANGO_will load onlyDJANGO_*variablesstrip_prefix: whether strip prefix when loading variables; defaultTrue; f.e.DJANGO_SECRETwill be loaded asSECRETifprefix=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 onlyDJANGO_*variables--strip-prefix: whether strip prefix when loading variables; defaultTrue; f.e.DJANGO_SECRETwill be loaded asSECRETifprefix=DJANGO_--dry-run: only display parsed.envresult 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
- https://github.com/jezdez/envdir - runs another program with a modified environment according to files in a specified directory
- https://github.com/theskumar/python-dotenv - Reads the key,value pair from .env and adds them to environment variable
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e05fa2da610625d0d537f464a9b24e4c66896acfb772c3a7e28331d299e77640
|
|
| MD5 |
2a963334dc95194d9909d84149efd83f
|
|
| BLAKE2b-256 |
b7e3b90e1608f76c05666d7adee568f2e08da23317c302ec297d79393edf78b7
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f3e36aa4e25bb054c4200d915be1b5faf3096f7791865b5be42feb9f056b2ff1
|
|
| MD5 |
babf6a4541539dec6076d18109e1fb64
|
|
| BLAKE2b-256 |
a151c52e100777237e824f2474a22672ce72d9be8cbc6d0979103fcc3a191636
|