mb.get_secret(secret_name, ...)
Retrieve a secret value previously stored in Modelbit. Returns the secret value as a string.
Parameters
secret_name
:str
The name of the secretignore_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.
Examples
Fetch a secret
my_api_key = mb.get_secret("SECRET_API_KEY")
Fetch a secret if it exists
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.