Hushfang

Hushfang / Guide

Getting started

Installation

Hushfang requires Python 3.11 or later. To add it to a uv project, run

uv add hushfang

To install it with pip in your active environment, run

python -m pip install hushfang

Run the example

import logging
from urllib.parse import quote

from pydantic import BaseModel, SecretStr

from hushfang import RedactingFormatter, SecretRegistry


class Settings(BaseModel):
    api_key: SecretStr


settings = Settings(api_key="cedar/47+mint")
registry = SecretRegistry()
registry.register_model(settings)

handler = logging.StreamHandler()
handler.setFormatter(RedactingFormatter(registry, "%(message)s"))
logger = logging.getLogger("example.sdk")
logger.propagate = False
logger.addHandler(handler)


def sdk_retry(request_id: str, attempt: int, token: str) -> None:
    # Simulate a client that includes the URL-encoded value in a retry message.
    logger.warning("request=%s attempt=%d rejected %s", request_id, attempt, quote(token, safe=""))


sdk_retry("r-17", 2, settings.api_key.get_secret_value())
# request=r-17 attempt=2 rejected ***

Explore Hushbench · Run the HTTPX example

How the registry works

Secret registration and redaction

Read the runtime registry guide

Coverage

Install the formatter on each text handler that needs masking. Register credentials before their first use. The secret handling guide covers model fields, explicit disclosure and exception handling.