Skip to main content

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 secret
  • ignore_missing: Optional[bool] If False an exception is raised if the secret doesn't exist. If True then no exception is raised and an empty string ("") is returned for secrets that don't exist. Default is False.

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