decorative-secrets

raw JSON →
0.12.14 verified Fri May 01 auth: no python

A library providing decorators for multi-source secret retrieval, allowing secrets to be fetched from environment variables, files, AWS Secrets Manager, and other backends. Current version is 0.12.14. Release cadence is irregular with frequent minor version bumps.

pip install decorative-secrets
error ModuleNotFoundError: No module named 'decorative-secrets'
cause Trying to import with hyphens instead of underscores.
fix
Use from decorative_secrets import secret (underscore).
error TypeError: secret() got multiple values for argument 'key'
cause Passing both a string and a keyword argument 'key' when the decorator expects only one.
fix
Use either @secret('KEY') or @secret(key='KEY'), but not both.
gotcha The 'secret' decorator returns the secret value as the first argument to the decorated function. If you don't expect an argument, your function will receive an extra argument.
fix Define your function with a parameter to accept the secret, e.g., `def func(secret_value):`.
deprecated The 'from_env' backend (used with `@secret('KEY', from_env=True)`) is deprecated in favor of the default behavior where environment variable keys are automatically detected.
fix Remove the `from_env=True` argument; just pass the environment variable name directly.
gotcha Using a period (.) in the key name may be misinterpreted as nesting. For example, 'my.secret' might be parsed as a path instead of a literal key.
fix Use underscores or other characters instead of periods, or wrap the key in quotes and use explicit backend configuration.

Retrieve a secret from an environment variable using the @secret decorator.

import os
os.environ['MY_SECRET_KEY'] = 'my-secret-value'

from decorative_secrets import secret

@secret('MY_SECRET_KEY')
def get_secret(val):
    return val

print(get_secret())