Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Redact Secret for Python

Deterministic secret detection and redaction for runtime data and AI context, for CPython, over the same Rust core that backs the JavaScript, Rust, and CLI surfaces of Redact Secret. Every built-in detector runs in Rust; there is no pure-Python fallback implementation to drift from it.

Scan text in your process before it reaches logs, persistence, telemetry, tool output, or model context. Detection is local and deterministic: no network calls, no telemetry, and the same input always gives the same result. Findings never include the matched secret.

Redact Secret is not a DLP platform and does not detect every secret: it finds supported credential formats only, and an empty finding list does not prove text is secret-free. It complements repository and history scanners rather than replacing them. Per-family support is published in the generated support matrix, not stated by hand here.

The distribution is redact-secret and the import name is redact_secret. The product name is Redact Secret everywhere; per PEP 503, redact-secret and redact_secret normalize to the same PyPI project identity, so no registry fallback name is needed — see docs/rust-workspace.md.

The version in the development manifests is not a published release. See release status for installable versions.

This directory is the canonical Python binding decision-release-bindings-in-lockstep requires before the separately created secret-scan-python GitHub repository (empty today) is archived with a redirect to here; that prepared redirect text lives in docs/python-repository-redirect.md.

Install

pip install redact-secret

Wheels are CPython 3.10+ abi3: one wheel per platform serves every supported interpreter, and installing one needs no Rust toolchain and no compiler. See Supported wheels. Where no wheel applies, pip falls back to the source distribution, which does need Rust — see Building from source.

Use

import redact_secret

findings = redact_secret.scan(text)
redacted = redact_secret.redact(text, findings)

# or, to guarantee the findings and the redacted text agree:
result = redact_secret.scan_and_redact(text)
result.text, result.findings

Ranges on every DetectedFinding and Finding are Unicode code point offsets (redact_secret.RANGE_UNIT == "unicode-code-points"), so they index a str the way Python itself does.

scan, redact, and scan_and_redact default to a 64 MiB input bound and a 50,000 finding-count bound, raising InputLimitExceededError/ FindingLimitExceededError rather than returning a truncated result. Pass limits=redact_secret.WholeInputLimits(max_input_bytes=..., max_findings=...) to raise or lower them.

For input that arrives in pieces, IncrementalSanitizer sanitizes a bounded session chunk by chunk. Independently scanning chunks is unsafe, because a credential may cross any chunk boundary; a session carries the boundary state that makes it safe. Limits are mandatory and are counted in UTF-8 bytes:

limits = redact_secret.IncrementalLimits(
    max_input_bytes=1_000_000,
    max_buffered_bytes=32_896,
    max_token_bytes=8_192,
    max_multiline_bytes=32_768,
)

with redact_secret.IncrementalSanitizer(limits) as session:
    first = session.append("api_key=SYNTHETIC_REVOKED_")
    second = session.append("INCREMENTAL_VALUE\nordinary text")
    final = session.finalize()

safe_text = first.text + second.text + final.text
# api_key=<SECRET_1>\nordinary text

Leaving the with block aborts a session that was not finalized, so whatever it still retained is discarded. A session's findings carry absolute code point offsets into the logical whole-session input, so they index "".join(chunks) exactly as the synchronous API's findings index the same joined string.

policy and formatter callbacks receive only normalized safe metadata, never the input or a matched value. A callback that raises, or that returns something other than the documented protocol, never propagates its own error: it becomes one of the fixed SecretScanError subclasses. There is no custom detector callback surface.

The package is typed (PEP 561): the wheel ships py.typed and a _native.pyi stub, so type checkers resolve the API without a stub package.

Supported wheels

Platform Architectures Wheel tag
manylinux (glibc 2.17+) x86_64, aarch64 cp310-abi3-manylinux_2_17_*.manylinux2014_*
musllinux (musl 1.2+) x86_64, aarch64 cp310-abi3-musllinux_1_2_*
macOS 11+ x86_64, arm64 cp310-abi3-macosx_*
Windows x64, arm64 cp310-abi3-win_*

Every wheel in that matrix is built and smoke-tested on its own architecture, on CPython 3.10 and 3.14, before a release candidate is accepted; see docs/python-packaging.md.

Building from source

The source distribution needs a Rust toolchain at or above the workspace MSRV (1.88, Rust 2024 edition). With cargo on PATH, pip install builds it like any other source install.

Without one, maturin's build backend downloads a toolchain into a local cache and continues. To refuse that instead and fail immediately with Cargo metadata failed. Do you have cargo in your PATH?, set:

MATURIN_NO_INSTALL_RUST=1 pip install --no-binary redact-secret redact-secret

Set it in any environment that must not fetch a toolchain over the network.

Development

This directory is a mixed Rust/Python maturin project. The crate is redact-secret-python, the native module is redact_secret._native, and the pure Python package lives under python/redact_secret/.

  • src/lib.rs owns CPython conversions, Unicode code point range conversion, and the synchronous scan/redact/scan_and_redact API: immutable finding and result types, sanitized exceptions, and the default policy and formatter helpers (decision-define-runtime-bindings).
  • src/incremental.rs owns the bounded incremental session: IncrementalSanitizer, its mandatory IncrementalLimits, the lifecycle states, and the incremental policy callback. Its CodePointIndex converts the core's absolute UTF-8 byte offsets to the absolute code point offsets a session reports, by recording only where the input's UTF-8 continuation bytes fall, never the characters themselves. Between successful calls it prunes offsets outside max_buffered_bytes; while processing a call it also indexes the incoming chunk, and its allocation can retain that peak capacity until the session ends. Bound host chunk sizes as well as session limits.
  • python/redact_secret/__init__.py re-exports the native module's public surface; python/redact_secret/_native.pyi and py.typed mark the package as typed.
  • tests/ runs against a built extension and exercises the shared conformance/ corpus, Unicode code point conversion, callback failure sanitization, placeholder safety, and determinism. The incremental suites add native-string partition invariance (test_incremental_partitions.py), astral character boundaries (test_incremental_unicode.py), and the canonical lifecycle, limit, callback, and failure-cleanup cases (test_incremental.py). They read the corpus from the repository, so they ship with neither the wheel nor the source distribution.
  • The extension-module Cargo feature is enabled only by maturin, so the crate still links during cargo test --workspace.
cd bindings/python
python3 -m venv .venv && source .venv/bin/activate
pip install '.[test]' maturin pytest
maturin develop
pytest

Rebuild with maturin develop after any change under src/; pytest imports the installed extension, not the Rust sources.

Packaging identity, the abi3 contract, and the wheel matrix are declared in [workspace.metadata.redact-secret] in the root Cargo.toml and enforced by scripts/check-python-package.py. Build and qualify artifacts with scripts/qualify-python-wheel.py; see docs/python-packaging.md.

Release files for redact-secret 0.1.0b7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for redact-secret 0.1.0b7
File Size Uploaded
redact_secret-0.1.0b7.tar.gz 316.2 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for redact-secret 0.1.0b7
File
redact_secret-0.1.0b7-cp310-abi3-win_arm64.whl CPython 3.10 abi3 Windows ARM64 Details
redact_secret-0.1.0b7-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details
redact_secret-0.1.0b7-cp310-abi3-musllinux_1_2_x86_64.whl CPython 3.10 abi3 Linux musl 1.2+ x86-64 Details
redact_secret-0.1.0b7-cp310-abi3-musllinux_1_2_aarch64.whl CPython 3.10 abi3 Linux musl 1.2+ ARM64 Details
redact_secret-0.1.0b7-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-64 Details
redact_secret-0.1.0b7-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64 Details
redact_secret-0.1.0b7-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details
redact_secret-0.1.0b7-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details

Total release size: 4.0 MB

Release files / redact_secret-0.1.0b7.tar.gz

Download URL redact_secret-0.1.0b7.tar.gz
Size 316.2 kB
Tags Source
SHA-256 checksum
How to use checksums
0ad7d302623759b438d9016d07beedc1de080fbfde3338a2d48c2ec442eb4ab7
BLAKE2b-256 checksum
How to use checksums
db13dfad484694b895bbf657b382cd8f88718825da9ce732a13cd82e2974d26e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 24, 2026.

Transparency log

Release files / redact_secret-0.1.0b7-cp310-abi3-win_arm64.whl

Download URL redact_secret-0.1.0b7-cp310-abi3-win_arm64.whl
Size 315.1 kB
Tags CPython 3.10 Windows ARM64 abi3
SHA-256 checksum
How to use checksums
afab02ff4a36a77adaa8ec8adfe8ded51aa8404cb6566fe1b3a4b8fbef3ddce2
BLAKE2b-256 checksum
How to use checksums
41c72d07538f928cd2ea74b98c13b0734edf899699d9673bb9cf2b3028fbc1ce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 24, 2026.

Transparency log

Release files / redact_secret-0.1.0b7-cp310-abi3-win_amd64.whl

Download URL redact_secret-0.1.0b7-cp310-abi3-win_amd64.whl
Size 329.2 kB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
f70905ab9ee32520f6ba8cc4f1685340d5b217076e203b902ee204205c7918e8
BLAKE2b-256 checksum
How to use checksums
58490219189f78f2a7e3b04c6374b683d5e1d09ad18e3abd1b5d8b98ac5717b6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 24, 2026.

Transparency log

Release files / redact_secret-0.1.0b7-cp310-abi3-musllinux_1_2_x86_64.whl

Download URL redact_secret-0.1.0b7-cp310-abi3-musllinux_1_2_x86_64.whl
Size 666.9 kB
Tags CPython 3.10 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
5d0a6b1463f02667061caa63dc4a25b5665550eb118f9507a2bf95fa3dfc6231
BLAKE2b-256 checksum
How to use checksums
97076f3b16f9725ca5d56a88c8c886de7921864ff09736e30ba76bc581d35822
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 24, 2026.

Transparency log

Release files / redact_secret-0.1.0b7-cp310-abi3-musllinux_1_2_aarch64.whl

Download URL redact_secret-0.1.0b7-cp310-abi3-musllinux_1_2_aarch64.whl
Size 623.9 kB
Tags CPython 3.10 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
e73d29d9feb47a14a3d5b7f4add3617f1a6925208a9a955e3a4f693c8147e99f
BLAKE2b-256 checksum
How to use checksums
beb69250bda8acac2252affeeff84dae9cb548f286cde2d16b50fb3fb610a996
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 24, 2026.

Transparency log

Release files / redact_secret-0.1.0b7-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL redact_secret-0.1.0b7-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 454.1 kB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
cabe27c76716c47ce34f98442e5d07777e36871f0f5e26749527ca97c49987e5
BLAKE2b-256 checksum
How to use checksums
08bc561e8ff3670d731737467c8b9ef019297af3c8ecd004460cc518c5f5a459
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 24, 2026.

Transparency log

Release files / redact_secret-0.1.0b7-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL redact_secret-0.1.0b7-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 445.5 kB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
79e1398d39601142be723b4353eb5df3eda34bceefee8a513c22c7d8045ac3ef
BLAKE2b-256 checksum
How to use checksums
6b681a29bee9ee3211e810ded57b9d60b980b1a2913226a22333d9482fca203c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 24, 2026.

Transparency log

Release files / redact_secret-0.1.0b7-cp310-abi3-macosx_11_0_arm64.whl

Download URL redact_secret-0.1.0b7-cp310-abi3-macosx_11_0_arm64.whl
Size 417.6 kB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
d712a2b428dfdffbbd54dacdb8cc31728711d1be42bef13df7f333ad4bd90df8
BLAKE2b-256 checksum
How to use checksums
81bcfee25b82a6ddae213190eff113d70ed3cb11e1a28a252b7845e3eeac0d59
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 24, 2026.

Transparency log

Release files / redact_secret-0.1.0b7-cp310-abi3-macosx_10_12_x86_64.whl

Download URL redact_secret-0.1.0b7-cp310-abi3-macosx_10_12_x86_64.whl
Size 426.6 kB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
8097975171cb8487e58c317fbff921d734b88efaf0ce13c654de90a64a65d95b
BLAKE2b-256 checksum
How to use checksums
b7b112f06cfd77669b30e5811503932fcdca052c92422680bc014492a3e6f626
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 24, 2026.

Transparency log
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page