get_secret
Retrieve a secret value previously stored in Modelbit. Returns the secret value as a string.
Parameters
mb.get_secret(name=, ...)
name
:str
The name of the secret.ignore_missing
:Optional[bool]
IfFalse
an exception is raised if the secret doesn't exist. IfTrue
then no exception is raised and an empty string (""
) is returned for secrets that don't exist. Default isFalse
.
Returns
str
if the secret exists. If the secret does not exist then an exception will be raised unless ignore_missing=False
is used.
Examples
Fetch a secret
To fetch the value of the secret SECRET_API_KEY
:
my_api_key = mb.get_secret("SECRET_API_KEY")
Fetch a secret if it exists
To store the value of a secret in an envvar, and ignore errors if the secret doesn't exist:
import os
os.environ["SECRET_API_KEY"] = mb.get_secret("SECRET_API_KEY", ignore_missing=True)
See also
- Learn how to manage secrets in Modelbit.