yera.tools.creds.snapshot
Read-only flat credential snapshot exposed to tool bodies.
Symbols
ToolCreds
Read-only snapshot of credentials available to a tool.
Wraps a flat dict[str, str] mapping dotted keys
(<group>.<subkey>) to their string values. Tools obtain an
instance via
tool_creds rather than
constructing one directly.
Example:
@yr.tool(creds=["db"])
def query(sql: str) -> list[dict]:
creds = yr.tool_creds()
host = creds.require("db.host")
port = creds.require("db.port")
...
Methods
ToolCreds.__init__
__init__(
credentials: dict[str, str],
) → NoneInitialize an immutable snapshot from resolved credential values.
Parameters
Dotted credential keys mapped to their resolved values.
ToolCreds.get
get(
key: str,
) → str | NoneLook up a credential by dotted key, returning None if absent.
Parameters
Dotted credential key, e.g. "openai.api_key".
Returns
The credential value, or None if no such key is configured.
ToolCreds.require
require(
key: str,
) → strLook up a credential by dotted key, raising if absent.
Parameters
Dotted credential key, e.g. "openai.api_key".
Returns
The credential value.
Raises
If no such key is configured.
ToolCreds.keys
keys() → list[str]Return the configured credential keys.
Returns
Dotted credential keys sorted alphabetically.
ToolCreds.__contains__
__contains__(
key: str,
) → boolCheck whether a dotted key is configured.
Parameters
Dotted credential key to test.
Returns
Whether the snapshot contains the key.
ToolCreds.__len__
__len__() → intReturn the number of configured credentials.
Returns
The number of keys in the snapshot.
ToolCreds.__repr__
__repr__() → strReturn a redacted representation of the snapshot.
Returns
A representation listing keys without credential values.