GitHub

redacted

API reference for redacted.

Redacted[A]: a value that does not show itself (Effect's Redacted).

str, repr, f-strings, logs (every fx.logger format, JSON included) and Cause.pretty print <redacted> (<redacted:label> with a label); value(r) gives the value back. Two redacted values are equal, and hash alike, when their values are::

key = redacted.make("sk-123", label="api key")
str(key)            # "<redacted:api key>"
redacted.value(key) # "sk-123"
AttributeTypeDescription
A_co= TypeVar('A_co', covariant=True)

Classes

Functions

make

make(value, *, label=None) -> Redacted[A]

Hide value; label shows in its text form.

ParameterTypeDescription
valueA
labelstr | None = None

Returns Redacted[A]

def make[A](value: A, *, label: str | None = None) -> Redacted[A]:
    """Hide ``value``; ``label`` shows in its text form."""
    return Redacted(value, label=label)

value

value(redacted) -> A

The hidden value. Raises ValueError once wipe_unsafe wiped it.

ParameterTypeDescription
redactedRedacted[A]

Returns A

def value[A](redacted: Redacted[A]) -> A:
    """The hidden value. Raises ``ValueError`` once ``wipe_unsafe`` wiped it."""
    hidden = redacted._value  # pyright: ignore[reportPrivateUsage]
    if isinstance(hidden, _Wiped):
        label = f' with label: "{redacted.label}"' if redacted.label is not None else ""
        raise ValueError(f"Unable to get redacted value{label}")
    return hidden

wipe_unsafe

wipe_unsafe(redacted) -> bool

Drop the hidden value; False if it was already gone.

ParameterTypeDescription
redactedRedacted[object]

Returns bool

def wipe_unsafe(redacted: Redacted[object]) -> bool:
    """Drop the hidden value; ``False`` if it was already gone."""
    if isinstance(redacted._value, _Wiped):  # pyright: ignore[reportPrivateUsage]
        return False
    object.__setattr__(redacted, "_value", _WIPED)
    return True