Skip to content

Python decorator for convenient loading of environment variables

License

Notifications You must be signed in to change notification settings

eghuro/atenvironment

Repository files navigation

@environment

Documentation Status Updates

Decorator for convenient loading of environment variables. @environment allows you to declare dependencies on environment variables so that it's clear what needs to be set. Also, any error handling is moved away making the code clearer.

Getting started

Install @environment from pip:

pip install atenvironment

Using @environment is as simple as:

from atenvironment import environment

@environment('API_KEY', 'TOKEN')
def check(a, b, c, key, token):
    # API_KEY is in key
    # TOKEN is in token

Then call the function as:

check(a, b, c)

Environment variables are checked and provided to the function as trailing parameters in order of declaration. In case the token is not in environment an atenvironment.EnvironMiss exception is raised. You can also provide your own error handling function. In addition, some environment variables can be loaded directly into object variable in case instance property is to be initialized.

See the docummentation for more details.

[ ~ Dependencies scanned by PyUp.io ~ ]

About

Python decorator for convenient loading of environment variables

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published