Skip to main content

secretscreen

CI Codecov OpenSSF Scorecard License: MIT Python PyPI Ruff

Detect and redact secrets in key-value pairs, dicts, and environment variables.

Best-effort defense-in-depth. Not a security boundary.

Install

pip install secretscreen

Quick start

from secretscreen import redact_pair, redact_dict, audit_dict, Mode

# Single pair
redact_pair("DB_PASSWORD", "hunter2")  # → "[REDACTED]"
redact_pair("APP_NAME", "myapp")  # → "myapp"

# Dict with recursion
redact_dict({"db": {"password": "x", "host": "localhost"}})
# → {"db": {"password": "[REDACTED]", "host": "localhost"}}

# Aggressive mode (adds entropy detection)
redact_dict(env, mode=Mode.AGGRESSIVE)

# Audit mode (structured findings, no mutation)
findings = audit_dict(env)
# → [Finding(key="DB_PASSWORD", reason="key_pattern:password", ...)]

# Custom safe suffixes (keys ending with these are never redacted)
redact_dict(env, safe_suffixes=("_config", "_enabled"))

Command line

The library only helps Python callers. The CLI covers the shell side — docker exec, Makefiles, CI logs, anything you are about to paste somewhere.

secretscreen tandoor.env                    # redact and print, cat-like
docker exec app env | secretscreen          # scrub a stream before it hits your terminal
secretscreen --audit config.json            # findings only, no values, exit 1 if any
secretscreen [FILE...]              reads stdin when FILE is omitted or '-'
  --audit                           report findings without values; exit 1 if any
  --format env|json|ini|dsn|auto    default: auto-detect from extension, then content
  --aggressive                      add entropy detection; more false positives
  --replacement TEXT                default: [REDACTED]

Redaction is structural, not line-based: it parses the format, so it catches DB_PASSWORD=hunter2 on the key name and rewrites postgres://admin:s3cr3t@host/db to postgres://admin:[REDACTED]@host/db without destroying the rest of the line. Comments, blank lines, quoting, export prefixes, INI sections and : separators all survive the round trip.

What the exit code means:

Code Meaning
0 Everything was parsed and screened
1 --audit found secrets
2 Something could not be parsed or read — see stderr

That third case is the one that matters. This is best-effort defense-in-depth, and a cat-replacement is exactly the tool people stop thinking about, so the CLI never prints unparsed content verbatim: a line it cannot structure is replaced with the redaction token, named on stderr, and turns the exit code non-zero. The same applies to values above the 64 KB detection cap — they are reported as unscanned rather than passed off as clean.

If you are scanning a git repository rather than config-shaped data, use gitleaks instead. That is a different job.

Detection layers

  1. Key-name denylist — substring match against ~30 known secret key patterns
  2. Structured value parsing — JSON, Python literals, DSN, INI, URL query params
  3. Value-format detection — 222 known formats via vendored gitleaks patterns (MIT)
  4. URL credential detection — partial redaction of user:pass@host URLs
  5. Entropy detection — Shannon entropy for machine-generated strings (aggressive mode only)

Contributing

Bug reports and pull requests welcome. See CONTRIBUTING.md.

Support

If you find secretscreen useful, consider buying us a coffee.

License

MIT. Gitleaks patterns are also MIT-licensed.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

secretscreen-0.2.1.tar.gz (60.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

secretscreen-0.2.1-py3-none-any.whl (42.4 kB view details)

Uploaded Python 3

File details

Details for the file secretscreen-0.2.1.tar.gz.

File metadata

  • Download URL: secretscreen-0.2.1.tar.gz
  • Upload date:
  • Size: 60.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for secretscreen-0.2.1.tar.gz
Algorithm Hash digest
SHA256 302615a3f232aa94c65f8b9dd595440541d27bc87e8e8a7b833834ee599d8d3a
MD5 85f6601924b4055051c89156ecce71ad
BLAKE2b-256 b1211efffd90a37478caca7d99a5f092e380fc0c01e1f7523c883d89678baa50

See more details on using hashes here.

Provenance

The following attestation bundles were made for secretscreen-0.2.1.tar.gz:

Publisher: publish.yml on featurecreep-cron/secretscreen

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file secretscreen-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: secretscreen-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 42.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for secretscreen-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 61bda5f08e14b05ca8b3d67f4b208f2f9da84ba6b2e45ea50fedf6df1ad5a84f
MD5 d4e7b942b41bdba9079d6fb1751805c2
BLAKE2b-256 3787047c01714f781bde8453e5ecf2ddc857348e2fa7386332ebe8748e0204d9

See more details on using hashes here.

Provenance

The following attestation bundles were made for secretscreen-0.2.1-py3-none-any.whl:

Publisher: publish.yml on featurecreep-cron/secretscreen

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.5.1

2 files

0.5.0

2 files

0.4.0

2 files

0.3.0

2 files

This release

0.2.1 This release

2 files

0.2.0

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page