Skip to main content

Source env.bash script to update environment

Project description

PyPI Build Status Coverage Report

Python module for sourcing a bash script to augment the environment. Supports Python 2.7 and 3.3+

Rationale

[12-factor apps](https://12factor.net/) require [configuration loaded from the environment](https://12factor.net/config).

That’s easy on a platform like Heroku, where the environment is preset by the user with [commands like heroku config:set](https://devcenter.heroku.com/articles/config-vars). But it’s messier in development and non-Heroku deployments, where the environment might need to be loaded from a file.

This package provides a mechanism for sourcing a Bash script to update Python’s environment (os.environ). There are reasons for using a Bash script instead of another configuration language:

  1. Environment variable keys and values should always be strings. Using a Bash script to update the environment enforces that restriction, so there won’t be surprises when you deploy into something like Heroku later on.

  2. Using a script means that the values can be sourced into a Bash shell, something that’s non-trivial if you use a different config language.

  3. For better or worse, using a script means that environment variables can be set using the full power of the shell, including reading from other files.

Commonly the external file is called env.bash, hence the name of this project.

Installation

Install from PyPI:

pip install envbash

Usage

Call load_envbash to source a Bash script into the current Python process. Any variables that are set in the script, regardless of whether they are explicitly exported, will be added to the process environment.

For example, given env.bash with the following content:

FOO='bar baz qux'

This can be loaded into Python:

import os
from envbash import load_envbash

load_envbash('env.bash')

print(os.environ['FOO'])  #=> prints BAR

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

envbash-1.0.0.tar.gz (3.7 kB view details)

Uploaded Source

File details

Details for the file envbash-1.0.0.tar.gz.

File metadata

  • Download URL: envbash-1.0.0.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for envbash-1.0.0.tar.gz
Algorithm Hash digest
SHA256 c0c478903b8a2fb88e93a83f5f027f7e3bec8ec565d7ddece1da6f4e9f670416
MD5 ae1f4caa6bbfc0d9773963211dc060d8
BLAKE2b-256 b77034462a5c110385759ed17e131642a962e95b6f9fbadd8822157b352c1ecd

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