Skip to main content

CLI tool to upload environment variables from local .env files to Heroku

Project description

heroku.env

https://img.shields.io/pypi/v/heroku_env.svg https://img.shields.io/travis/viseshrp/heroku_env.svg Documentation Status Documentation Status

Simple CLI tool to upload environment variables to Heroku from a .env file, through the Heroku CLI Toolbelt.

Disclaimer

This library was a quick personal project because we use Heroku a lot at work and I find it really annoying when you have to add env vars manually from your local environment every time. This is also my first venture into open source Python and my very first library on PyPI. If you’re a rockstar dev reading this, I cannot be happier and I cannot tell you how much your feedback would mean to me :) Thanks.

Installation

pip install heroku.env

Requirements

  1. Tested on Python 3.6+ but may work in Python 2.7+.

  2. Heroku CLI (Toolbelt) installed.

  3. A valid Heroku app name is required to run against.

  4. The absolute/relative path to the .env file is also needed, but if not provided, “.env” will be used as the default, which expects a file named .env to be present in the current working directory.

  5. Your Heroku API key (found here or by running this), for Heroku CLI to run and authenticate you.

Features

  • Auto-setting of all env vars from a .env file.

Examples:

$ heroku.env --app swimming-briskly-123 --env-file dot.env
  • Lines starting with # are considered comments in the env file and ignored.

Examples:

# Django settings module
DJANGO_SETTINGS_MODULE=portfolio.settings
  • Allow setting of alternate values by specifying alt_value=VALUE in comments of the env file.

For example, if you want to load the env vars from the .env file into a Heroku app running in production, you might want to use different values for some variables, than the ones in the .env file.

Examples of allowed usages:

I use a portfolio.env for my portfolio app running in Docker for local development. If I want the Heroku app to use a different value for DJANGO_SETTINGS_MODULE, I would do something like this:

# Django settings module alt_value=portfolio.prod_settings
DJANGO_SETTINGS_MODULE=portfolio.settings

OR

# Django settings module
# alt_value=portfolio.prod_settings
DJANGO_SETTINGS_MODULE=portfolio.settings

OR

# alt_value=portfolio.prod_settings
# Django settings module
DJANGO_SETTINGS_MODULE=portfolio.settings

NOTE: The alt_value needs to be on the line right before the actual env var you want to change. Also note that anything (except for trailing whitespace) specified after alt_value= is used as the alternate value, so be careful.

Any of these methods above will force the tool to replace the value for DJANGO_SETTINGS_MODULE with portfolio.prod_settings instead of the actual portfolio.settings, but only if you run with the option --set-alt like this:

$ heroku.env --app swimming-briskly-123 --env-file portfolio.env --set-alt
  • Secure, does not store your API key anywhere.

Its just a light wrapper around the Heroku CLI/Toolbelt and any access to Heroku only happens through the toolbelt.

The API key can be set as an environment variable (as HEROKU_API_KEY before running the tool) or passed with --api-key or -k.

If the API key is set as an environment variable, it will be automatically read.

If it is not set in any way, you will be given a password-type prompt to enter it.

It is recommended for security purposes that you set it as an environment variable before running the tool, like this:

$ export HEROKU_API_KEY=a1b12c24-ab1d-123f-5678-1234b12a0a1b

OR you can wait for the prompt.

This is not recommended, but still available as an option.

$ heroku.env --app swimming-briskly-123 --env-file dot.env --api-key a1b12c24-ab1d-123f-5678-1234b12a0a1b

See all options with:

$ heroku.env --help

Credits

History

0.4.0 (2018-12-30)

  • Detect Heroku installation and issues and launch appropriate URLs in browser to guide user

  • Minor improvements

0.3.0 (2018-12-29)

  • add feature to set alternate values during run

  • cleanup and minor improvements

0.2.0 (2018-12-24)

  • First release on PyPI.

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

heroku.env-0.4.0.tar.gz (13.4 kB view hashes)

Uploaded Source

Built Distribution

heroku.env-0.4.0-py2.py3-none-any.whl (9.4 kB view hashes)

Uploaded Python 2 Python 3

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