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.0.1.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.0.1-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for inject_environment_variables-1.0.1.tar.gz
Algorithm Hash digest
SHA256 4fd271d78849737cc1be59eb3c27515f44a12b29755135ea0f7fc183c77520b3
MD5 cfe602a214a035a42583c2e332d13084
BLAKE2b-256 0cc1384d874963195dbe12d5c94f381c57892c288587b69d6729d62162bc624c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for inject_environment_variables-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 449637894d3ce60b62ea447881716a304657f69b96f9de1ca178b1316853c6d5
MD5 33c3bab4afff35b23b53835352d26489
BLAKE2b-256 15215551ebe3bb89a6f13d3f32c4d1d88f6c8749263eab959f3782e51c52b270

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