Simple and fast secret detection. Scan strings and files for secret keys, API tokens, and credentials.
- High Performance: Regex matching powered by Rust with parallel processing
- Multiple Secret Types: Detects various types of credentials and keys
- Easy Integration: Simple Python API with both programmatic and CLI interfaces
- AWS Credentials
- OpenAI API Tokens (sk-...)
- Anthropic API Keys (sk-ant-...)
- Private Keys
- JWT Tokens
- Basic Auth Credentials
- NPM Tokens
pip install fastsecretsfrom fastsecrets import detect
# Scan a single string
secrets = detect("AKIAIOSFODNN7EXAMPLE")
for secret in secrets:
print(f"Found {secret.secret_type}: {secret.value}")
# Scan multiple strings
test_strings = [
"sk-aBcDeFgHiJkLmNoPqRsTT3BlbkFJuVwXyZaBcDeFgHiJkLmN",
"AKIAIOSFODNN7EXAMPLE",
"not_a_secret_key"
]
for test_string in test_strings:
results = detect(test_string)
if results:
for secret in results:
print(f"Secret type: {secret.secret_type}")
print(f"Secret value: {secret.value}")
else:
print("No secrets found")
# detect only specific types
results = detect("some string", secret_types=["openai", "anthropic"]) Scan files for secrets:
fastsecrets --file path/to/your/file.txtThe CLI will:
- Scan the file line by line
- Print any secrets found with line numbers
- Exit with code 1 if secrets are found (useful for CI/CD pipelines)
- Exit with code 0 if no secrets are found
Example output:
config.txt:5: [AWS Access Key ID] AKIAIOSFODNN7EXAMPLE
config.txt:12: [OpenAI Token] sk-aBcDeFgHiJkLmNoPqRsTT3BlbkFJuVwXyZaBcDeFgHiJkLmN
- Rust (latest stable)
- Python 3.8+
uvfor Python package management
# Clone the repository
git clone https://github.com/yourusername/fastsecrets.git
cd fastsecrets
# Install dependencies
uv pip install -e ".[tests]"
# Build the Rust extension
maturin develop# Run Python tests
pytest python/tests/
# Run Rust tests
cargo test- Create a new detector module in
src/secrets/(e.g.,src/secrets/stripe.rs) - Implement the detection function with regex patterns
- Add the detector to
src/lib.rsin the parallel detection pipeline - Add tests in both Rust and Python