Hushfang
Hushfang masks Pydantic secrets in formatted Python logs, including values revealed to a client or SDK. A log handler applies the registry to the formatted message, including exception chains, stack text and interpolated arguments. The library depends only on Pydantic.
Design principles for logging secrets · Hushbench · Detailed test report
Run the example
From a checkout with uv and Python 3.11 or later:
uv sync --locked
uv run --no-sync python demo.py
import logging
from pydantic import BaseModel, SecretStr
from hushfang import RedactingFormatter, SecretRegistry
class Settings(BaseModel):
api_key: SecretStr
settings = Settings(api_key="example-token-42")
registry = SecretRegistry()
registry.register_model(settings)
handler = logging.StreamHandler()
handler.setFormatter(RedactingFormatter(registry, "%(message)s"))
logger = logging.getLogger("client")
logger.propagate = False
logger.addHandler(handler)
logger.warning("Retrying with credential %s", settings.api_key.get_secret_value())
# Retrying with credential ***
Each registry belongs to its application or worker. Register secrets before clients can log them. Register replacements before rotating credentials. Old values remain available for delayed log messages until the registry is cleared or released. The registry holds sensitive values and reversible representations in memory.
Coverage
Secret types, validation, disclosure and exceptions · Cryptographic test vectors
- Register individual
SecretStrandSecretBytesinstances, or walk stored fields on an already validated model. The walk includes excluded fields, extras, nested models and standard containers. It handles cycles and skips computed properties. - Matching covers complete literals, Python and JSON escapes, standard and URL-safe padded Base64, hexadecimal, and common URL encodings. For a URL with credentials, the registry also covers its password and Basic credentials encoded as UTF-8 or Latin-1 when representable. A validated
Secret[HttpUrl]can be registered directly. - Overlapping matches are merged. Registering a short value can also mask ordinary text containing it. With the default policy, fragments of a truncated credential may survive. Select
SecretRegistry(token_mode="delimited")for clients that log token fragments. - Pass
mask_extra={"password"}to the formatter to replace that top-level log-record field even if its value is unknown. The same rule applies to nested mapping keys in messages, arguments and extras. - Install the formatter on each text handler that needs masking. Direct writes, separate telemetry exporters, validation failures before registration and logs emitted before registration are outside its coverage. A formatting failure emits a fixed diagnostic so the logging error path cannot echo the bad arguments.
Test and compare
Hushbench is the benchmark workspace member. It compares Hushfang, Python's standard formatter, logmask and loggingredactor on the same synthetic records. Reports show exact output, exposed canaries, altered public controls, dropped records and formatting cost. Expand a case in the HTML report to see the original event alongside each adapter's output.
uv sync --locked --all-packages
uv run --no-sync hushbench --output hushbench-report
uv run --no-sync ruff check .
uv run --no-sync ruff format --check .
uv run --no-sync ty check
CI runs the library tests and benchmark on Python 3.11, 3.12, 3.13, 3.14 and 3.15. The combined artifact contains an offline HTML index with a report for each interpreter. Results by scenario · Corpus and metrics · CI runs and downloads
The CI artifact includes a second report from 1,630 public cryptographic test events on each Python version. Sources and reproduction
Packaging
The library and benchmark share a uv lockfile. Installing Hushfang alone brings in Pydantic. The release rehearsal builds the library's wheel and source distribution and tests each in a clean environment. Packaging and release workflow
Related Pydantic experiment
An unsuccessful model validation can include the original input before a secret wrapper exists. On Pydantic 2.14.4, hide_input_in_errors=True hides input when printing the exception. Structured outputs still include it unless the caller passes include_input=False. The accompanying fork changes that default for structured errors and preserves explicit overrides. Experimental patch and regression tests | Pydantic issue 7461
Metadata
Release files for hushfang 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| hushfang-0.1.0.tar.gz | 17.6 kB | Without provenance | Details for hushfang-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| hushfang-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for hushfang-0.1.0-py3-none-any.whl |
Total release size: 37.5 kB
Release files / hushfang-0.1.0.tar.gz
| Download URL | hushfang-0.1.0.tar.gz |
|---|---|
| Size | 17.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
af19a4caacbf91c41247440827140b497a17769b88f7b2e9bdd5ed09ed17f637
|
|
BLAKE2b-256 checksum How to use checksums |
1ecf7e43c852d11a91ccf1c2fb9b3e92843a262a836232670e7f5a3b3c51960e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.13 {"installer":{"name":"uv","version":"0.13.13","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / hushfang-0.1.0-py3-none-any.whl
| Download URL | hushfang-0.1.0-py3-none-any.whl |
|---|---|
| Size | 20.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e2ab5fcae2f591f3d70288277e64a113c41da970397b5d567fb9c0b649806e4c
|
|
BLAKE2b-256 checksum How to use checksums |
52d29bbfb9b261baac6be8ca21e0648e5d09575e72983eb35087489c6915dec4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.13 {"installer":{"name":"uv","version":"0.13.13","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for hushfang 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.