Skip to main content

Read environmental variables

Project description

Helper function to read the environment variables in the development machine and on the production machine (only for heroku.com)

What is the purpose of this library

This Library will help you read the environment variables needed to run your software

  • An example of the environment variables would be:
    • database_login = datamaster

    • database_password = asdlf@#$kkLK!@)(“”)

    • DATABASE_URL = postgres://dsdsfd:asdfasgsdfgjjkdty.compute-1.amazonaws.com:532/jj4566ls

You are likely to have the variable stored differently in your development and production environment:

  • In your development/local machine:
    • these files are stored in a local text file (usually called .env)

    • your code will open the file, parse the text and read the variable

  • If your production environment is heroku.com
    • you can get the variables by os.environ()

As you can see, the code to read the env variable is different in the development machine and the production machine

Envars a function that will read it transparently from the development or production machine using the same code

How to use this library

Usage:

import envars.envars as envars
e_dct = envars.getenvars()

The environment variables are now in e_dct. Assuming you are running on a local machine and have a .env file that looks like this:

a=1
b=2

You can look at the values in e_dct:

>> print e_dct
defaultdict(<function <lambda> at 0x10cddbd70>, {'a': '1', 'b': '1'})

>> print e_dct['a']
'1'

If you are on the production machine at heroku.com, make sure you have the following variable in the heroku environment:

ENV_NOW=production

Envars uses this as a sign that you are on the production environment and will read it correctly. Now, on the production environment, you code will do the following:

>> print e_dct
defaultdict(<function <lambda> at 0x10cddbd70>, {"ENV_NOW":"production", 'a': '1', 'b': '1'})

>> print e_dct['a']
'1'

>> print e_dct['ENV_NOW']
'production'

Limitations of this library

Designed only for Heroku.com as production environment

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

envars-0.3.5.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

envars-0.3.5-py2.py3-none-any.whl (6.3 kB view details)

Uploaded Python 2Python 3

File details

Details for the file envars-0.3.5.tar.gz.

File metadata

  • Download URL: envars-0.3.5.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.10.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.7.4

File hashes

Hashes for envars-0.3.5.tar.gz
Algorithm Hash digest
SHA256 3fd2bfae9978b9b0809b5b7cf4001d7c1e82420af0fe0abdf1e29d3a4a885baa
MD5 2495380f745462f503ced9087ff9789c
BLAKE2b-256 5d524a5b482e86710cd347e7f26e84c3405ad2509d75f1c5530d1c667097ebe0

See more details on using hashes here.

File details

Details for the file envars-0.3.5-py2.py3-none-any.whl.

File metadata

  • Download URL: envars-0.3.5-py2.py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.10.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.7.4

File hashes

Hashes for envars-0.3.5-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 27b6e10830980d34b6cfaf5dae5b3babde4fb6f1aff26e9b358dbb5eb694c942
MD5 3ad0c6bdfce670973e9b5efcb919293e
BLAKE2b-256 a1defea26d8bea45ca29c2966b4f222dec59a33b37bfc3354e329d47f4067afd

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