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 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.

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.

No release is authorized by the version currently in the development manifests. Installation applies only after a separately approved release.

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.

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.0b4

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.0b4
File Size Uploaded
redact_secret-0.1.0b4.tar.gz 170.4 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for redact-secret 0.1.0b4
File
redact_secret-0.1.0b4-cp310-abi3-win_arm64.whl CPython 3.10 abi3 Windows ARM64 Details
redact_secret-0.1.0b4-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details
redact_secret-0.1.0b4-cp310-abi3-musllinux_1_2_x86_64.whl CPython 3.10 abi3 Linux musl 1.2+ x86-64 Details
redact_secret-0.1.0b4-cp310-abi3-musllinux_1_2_aarch64.whl CPython 3.10 abi3 Linux musl 1.2+ ARM64 Details
redact_secret-0.1.0b4-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.0b4-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64 Details
redact_secret-0.1.0b4-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details
redact_secret-0.1.0b4-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details

Total release size: 3.5 MB

Release files / redact_secret-0.1.0b4.tar.gz

Download URL redact_secret-0.1.0b4.tar.gz
Size 170.4 kB
Tags Source
SHA-256 checksum
How to use checksums
5c14e5874dbe7a9361c7be7a483c95d4f75dfd40ce7d3145cec0bc829e39a079
BLAKE2b-256 checksum
How to use checksums
fee8ad69766d5566b3ca70e403ca6e675071f2fd82a5d233906225bf233e2305
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 17, 2026.

Transparency log

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

Download URL redact_secret-0.1.0b4-cp310-abi3-win_arm64.whl
Size 270.0 kB
Tags CPython 3.10 Windows ARM64 abi3
SHA-256 checksum
How to use checksums
daa59ee45160c8db12ada33d882e93656444c0069b89bc2c4ac144f3065621b9
BLAKE2b-256 checksum
How to use checksums
e89e539e40e4764e4132031068743808246335131a190b7f1134e46d89852a66
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 17, 2026.

Transparency log

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

Download URL redact_secret-0.1.0b4-cp310-abi3-win_amd64.whl
Size 282.1 kB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
ca146bb4bbcb2c63d28f3e40344a9bc5dc13e08cb76b6e5093edf46a8023fa05
BLAKE2b-256 checksum
How to use checksums
ae359760b0ca21f973f9fa9c048315f787335c58e6079142cc2c7080a7b933c6
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 17, 2026.

Transparency log

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

Download URL redact_secret-0.1.0b4-cp310-abi3-musllinux_1_2_x86_64.whl
Size 616.2 kB
Tags CPython 3.10 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
0f49c25471c1b6810c23b8fbca573834641f9760bf3cf64353ca7d04f731da6b
BLAKE2b-256 checksum
How to use checksums
e0c55a2cb39cc162a3f16bca474722066ef94eea25bb33dca00bad7a8ad0b80f
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 17, 2026.

Transparency log

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

Download URL redact_secret-0.1.0b4-cp310-abi3-musllinux_1_2_aarch64.whl
Size 575.3 kB
Tags CPython 3.10 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
7e88d15dfd36ec982c72f01cf6e1482d337278b88bca4724fc93491d9ab93638
BLAKE2b-256 checksum
How to use checksums
a82bafdf9d2a1e77dbb9151932c78554b118f9bd9aa8c7ff0059183ca8d33a9b
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 17, 2026.

Transparency log

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

Download URL redact_secret-0.1.0b4-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 403.7 kB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
ab60a0ed43f047ba28a727f50226bdb46b9194f10eb6d07633c5bf754fbd09c7
BLAKE2b-256 checksum
How to use checksums
21d7dcc21818930fdb6c44a5c6b72d321ef51f70a831eace904de27f7a005da1
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 17, 2026.

Transparency log

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

Download URL redact_secret-0.1.0b4-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 396.0 kB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
3a4963ce9de599dfe383dc0fa9369c8765674e8572d6f55e0e422051998df9a8
BLAKE2b-256 checksum
How to use checksums
46e5d6bffb7ab45cae97626651477adc3a6976b3ba2ad175c494466fa3856be7
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 17, 2026.

Transparency log

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

Download URL redact_secret-0.1.0b4-cp310-abi3-macosx_11_0_arm64.whl
Size 370.3 kB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
ee9db7a6819aca194a76b29b14fd8147a57552c904a9e0005efe147f5edab95e
BLAKE2b-256 checksum
How to use checksums
994175cf67f61a10612da0be5b714f3da4a24c7152fe47d3a77801516af36c45
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 17, 2026.

Transparency log

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

Download URL redact_secret-0.1.0b4-cp310-abi3-macosx_10_12_x86_64.whl
Size 378.9 kB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
baee9dd4e25f4123cd0824eff71a2088d198f5bfc7098e98a720bf2996da082d
BLAKE2b-256 checksum
How to use checksums
679b0c6c51c5617104ad9cf59741492ef7e0a14a3736a18209663e39197e12e8
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 17, 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