Skip to main content

Environment variable composition layer for tools and processes.

Project description

envstack

Environment variable composition and activation layer for tools and processes.

envstack is what .env files wish they were when they grew up.

Why envstack?

  • Hierarchical environment composition
  • Explicit precedence and overrides
  • Late-bound environment activation
  • Shared, policy-driven environments
  • Inspectable and deterministic behavior

envstack focuses on configuration and activation, not dependency resolution.

For the core concepts, see docs/index.md.

Installation

The easiest way to install:

pip install -U envstack

Quickstart

Start by getting the latest default.env example file:

curl -o \
default.env \
https://raw.githubusercontent.com/rsgalloway/envstack/master/examples/default/default.env

Running envstack will launch a new shell session with the resolved environment:

$ envstack
🚀 Launching envstack shell... (CTRL+D or "exit" to quit)
(prod) ~$ echo $ENV
prod

To inspect the unresolved environment (before variable expansion):

$ envstack -u
DEPLOY_ROOT=${ROOT}/${ENV}
ENV=prod
ENVPATH=${DEPLOY_ROOT}/env:${ENVPATH}
HELLO=${HELLO:=world}
LOG_LEVEL=${LOG_LEVEL:=INFO}
PATH=${DEPLOY_ROOT}/bin:${PATH}
PS1=\[\e[32m\](${ENV})\[\e[0m\] \w\$ 
PYTHONPATH=${DEPLOY_ROOT}/lib/python:${PYTHONPATH}
ROOT=/mnt/pipe
STACK=default
$ envstack -r DEPLOY_ROOT
DEPLOY_ROOT=/mnt/pipe/prod

How envstack finds environments

envstack discovers environment definitions via the ENVPATH environment variable. ENVPATH is to envstack what PATH is to executables:

ENVPATH=/path/to/dev/env:/path/to/prod/env

In this case, environments in dev override or layer on top of environments in prod.

Converting .env files

Convert existing .env files to envstack by piping them into envstack:

cat .env | envstack --set -o out.env

Running Commands

To run any command line executable inside of an environment stack, where [COMMAND] is the command to run:

$ envstack [STACK] -- [COMMAND]

For example:

$ envstack -- echo {ENV}
prod

Example of injecting environment into a subprocess:

$ echo "console.log('Hello ' + process.env.ENV)" > index.js
$ node index.js 
Hello undefined
$ envstack -- node index.js 
Hello prod

Documentation

  • Design & philosophy → docs/design.md
  • Examples & patterns → docs/examples.md
  • Tool comparisons → docs/comparison.md
  • FAQ & gotchas → docs/faq.md
  • API docs → docs/api.md

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

envstack-0.9.6.tar.gz (55.4 kB view details)

Uploaded Source

File details

Details for the file envstack-0.9.6.tar.gz.

File metadata

  • Download URL: envstack-0.9.6.tar.gz
  • Upload date:
  • Size: 55.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.8.10

File hashes

Hashes for envstack-0.9.6.tar.gz
Algorithm Hash digest
SHA256 9c40c262df77eabf9d66dafbbbcbde3f6b9ec28d5d648e72dbcefee3b6237e2d
MD5 85f7290ff411ba36404ae9700a5cfadf
BLAKE2b-256 f086e8451b04c65c5b7f5f43fe2355429924865c7e8ab63f3b81cd4702c133a3

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