Skip to content

examples#

Refreshing Dynamic Settings and Secrets in Your Configuration

In your options, you can include callable functions designed to refresh dynamic values and secrets as needed. This example demonstrates exactly that.

Refreshing dynamic settings and secrets in your configuration

import json

from mltraq.opts import options
from mltraq.utils.bunch import Bunch

# Defining how to load the secrets
options().set(
    "secrets", lambda: Bunch(json.loads(open("secrets.json").read()))
)

# Get the callable to retrieve the secrets
get_secrets = options().get("secrets")

# The option value is a callable, no data is stored in plain text
print(f"Secrets retriever: {get_secrets}")

# Whenever we call it, the secrets are reloaded from the json file
print(f"API_KEY value: {get_secrets()['API_KEY']}")
Output
Secrets retriever: <function local_python_func.<locals>.<lambda> at 0x15ab52f70>
API_KEY value: 0000-1111-2222-3333