yera.tools.creds.snapshot

Read-only flat credential snapshot exposed to tool bodies.

Symbols

class ToolCreds — Read-only snapshot of credentials available to a tool.

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

get — Look up a credential by dotted key, returning ``None`` if absent.
require — Look up a credential by dotted key, raising if absent.
keys — Return the configured credential keys, sorted alphabetically.
__contains__ — Check whether a dotted key is configured.
__len__ — Number of configured credentials.
__repr__ — Repr string for ToolCreds.

ToolCreds.get

get(
    key: str,
) → str | None

Look up a credential by dotted key, returning None if absent.

Parameters

key
type: str

Dotted credential key, e.g. "openai.api_key".

Returns

type: str | None

The credential value, or None if no such key is configured.

ToolCreds.require

require(
    key: str,
) → str

Look up a credential by dotted key, raising if absent.

Parameters

key
type: str

Dotted credential key, e.g. "openai.api_key".

Returns

type: str

The credential value.

Raises

CredentialKeyError

If no such key is configured.

ToolCreds.keys

keys() → list[str]

Return the configured credential keys, sorted alphabetically.

ToolCreds.__contains__

__contains__(
    key: str,
) → bool

Check whether a dotted key is configured.

ToolCreds.__len__

__len__() → int

Number of configured credentials.

ToolCreds.__repr__

__repr__() → str

Repr string for ToolCreds.