Skip to main content

Simple tools for temporatily injecting variables into the environment

Project description

Inject Environment Variables

A testing and development tool for temporarily injecting environment variables.

Installation

pip install inject-environment-variables

Usage

Variables can be injected into the environment via either a with statement or a decorator.

With statement

Variables specified in the EnvironmentVariableInjector.

When the with exits the environment (os.environ) will be reset to how it was when the statement enters. Meaning any changes to the environment during the statement will be lost.

import os

from inject_environment_variables import EnvironmentVariableInjector

with EnvironmentVariableInjector({
  'VARIABLE_1': 'foo',
  'VARIABLE_2': 'bar'
}):
    print(os.getenv('VARIABLE_1')) 

Decorator

Variables can be specified by decorating a function with the inject_environment_variables decorator.

These changes to the environment are only active for the duration of the decorated function. At the end of the function the environment will be reset to how it was when the function started, meaning any changes to the environment during the statement will be lost.

import os

from inject_environment_variables.decorator import inject_environment_variables


@inject_environment_variables({
    'VARIABLE_1': 'foo',
    'VARIABLE_2': 'bar'
})
def test_environment_variables():
    print(os.getenv('VARIABLE_1')) 

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

inject_environment_variables-1.1.0.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

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

inject_environment_variables-1.1.0-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file inject_environment_variables-1.1.0.tar.gz.

File metadata

File hashes

Hashes for inject_environment_variables-1.1.0.tar.gz
Algorithm Hash digest
SHA256 c6fffa553a58b0fd276b02dbabd3310e033d605098ef691c5f8721ac33c9cb6c
MD5 18578528f207caaee61eb9d96acfee52
BLAKE2b-256 e30976f7e95359be30e62abafa9720753e75149b84b22ab20e64262342678e39

See more details on using hashes here.

File details

Details for the file inject_environment_variables-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for inject_environment_variables-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c47cb2b44cf503acacfbc93f830a24ea53f3582eab87d145a28ab08295dfb8bb
MD5 684a83dd024084959e6c50ca434f1f0b
BLAKE2b-256 4bfccbdb881b425ae952a398ce5bfef96714163201bfb4315083bb6e6a70dfcf

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