Registry / auth-security / detect-secrets

detect-secrets

JSON →
library1.5.0pypypi✓ verified 25d ago

Detect-secrets is a tool designed to identify and prevent sensitive information, such as API keys, passwords, and other credentials, from being committed into source code repositories. It leverages various detectors, including regex, keyword, and optional machine learning-based algorithms. The current version is 1.5.0, with minor releases typically occurring every few months.

pip install detect-secrets
INSTALL
IMPORT
SIG · DETECT-SECRETS
D
detect-secrets
auth-securitypythonv1.5.0
Install
2.4s avg
Import
515ms
Disk
23MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.5.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.531s · 24.2MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 2.4s · import 0.498s · 25MB
23MB installed
● package 23MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

SecretsCollection
from detect_secrets import SecretsCollection
from detect_secrets.core.usage import run_as_library
run_as_library
from detect_secrets.core.usage import run_as_library
constants
from detect_secrets import constants

This quickstart demonstrates how to programmatically scan a temporary directory containing a file with simulated secrets using `detect-secrets`. It initializes a temporary directory, creates a file with some fake credentials, and then uses `run_as_library` to perform the scan and print the detected secret types.

import os import tempfile from pathlib import Path from detect_secrets.core.usage import run_as_library def run_detect_secrets_scan(): with tempfile.TemporaryDirectory() as tmpdir: repo_path = Path(tmpdir) # Create a dummy file with a fake secret (repo_path / "my_project").mkdir() (repo_path / "my_project" / "config.py").write_text( "API_KEY = 'AKIAIOSFODNN7EXAMPLE' # This is a fake AWS key, DO NOT USE DB_PASSWORD = 'supersecretpassword123' SECRET_PHRASE = 'NotARealSecret' ") print(f"Scanning directory: {repo_path}") # Run the scan # 'plugins_used': None lets detect-secrets use its default plugin set. # 'secret_type_mapping': None uses default mappings. # 'mount_paths': Specify the path to scan. scan_results = run_as_library( plugins_used=None, secret_type_mapping=None, mount_paths=[str(repo_path)] ) # Process results if scan_results.data: print("\n--- Detected Secrets ---") for filepath, secrets in scan_results.data.items(): print(f"File: {filepath}") for secret in secrets: print(f" - Type: {secret.type}, Hashed Secret: {secret.hashed_secret}") else: print("\nNo secrets detected.") if __name__ == '__main__': run_detect_secrets_scan()
detect-secrets --version
Debug
Known issues
breakingSupport for Python 3.6 and 3.7 was dropped in v1.5.0. Python 3.8 support will also be removed in a future release (likely after its EOL in October 2024).
fix
Upgrade your Python environment to 3.9 or higher to maintain compatibility and receive updates.
affects: >=1.5.0
gotchaThe ML-based `gibberish-detector` (introduced in v1.1.0) is not included in the default installation. It requires an 'extra' package.
fix
Install `detect-secrets` with the `[ml]` extra: `pip install 'detect-secrets[ml]'`.
affects: >=1.1.0
gotchaFor effective use, especially with `pre-commit` hooks, `detect-secrets` heavily relies on configuration files (`.detect-secrets.yaml`) and a baseline file (`.secrets.baseline`). Skipping these can lead to excessive false positives or missed secrets.
fix
Initialize your repository with `detect-secrets init` to create a default config, and generate a baseline with `detect-secrets scan --baseline .secrets.baseline` to ignore existing secrets.
affects: All versions
Upgrade
Version history
1.5.0latest on PyPI · released May 6, 2024
Audit
Dependencies
scikit-learnoptionalRequired for the optional ML-based gibberish-detector feature. Installed via the `[ml]` extra.
Agent activity
26 hits · last 30 days
node
24
OpenAI (training)
1
Resources
detect-secrets — pip install detect-secrets · libregistry