TruffleHog Regexes
trufflehogregexes is a Python package that provides the core regular expressions used by the TruffleHog secrets scanner. It offers a structured list of dictionaries, each containing a regex pattern, ID, name, and tags for various sensitive information. Currently at version 0.0.7, it has a low release cadence, primarily serving as a data dependency for the main TruffleHog application.
Common errors
-
AttributeError: module 'trufflehogregexes' has no attribute 'get_regexes'
cause Attempting to call a non-existent function to retrieve the regexes list, assuming a common getter pattern.fixThe regex list is directly exposed as a module-level variable. Use `from trufflehogregexes import regexes` and then access `regexes` directly. -
TypeError: 'list' object is not callable
cause Trying to call the `regexes` variable as if it were a function, e.g., `regexes()`.fix`regexes` is a list, not a function. Access its elements using indexing (`regexes[0]`) or iterate over it directly. -
NameError: name 'regexes' is not defined
cause Attempting to use `regexes` without importing it explicitly, especially after `import trufflehogregexes` without specifying `trufflehogregexes.regexes`.fixEnsure you explicitly import `regexes` using `from trufflehogregexes import regexes`, or access it via the module namespace as `trufflehogregexes.regexes` after `import trufflehogregexes`.
Warnings
- gotcha The `regexes` list is a module-level variable, not a function. Do not attempt to call it or use a `get_regexes()` style accessor.
- gotcha This package provides only the regular expression patterns as data; it does not include any regex matching or scanning functionality. Users must integrate their own regex engine (e.g., Python's `re` module) to apply these patterns.
- gotcha As a pre-1.0.0 package (current version 0.0.7), the structure of regex entries (e.g., dictionary keys like 'id', 'name', 'regex', 'tags') might change in minor versions without strict backward compatibility guarantees.
Install
-
pip install trufflehogregexes
Imports
- regexes
from trufflehogregexes import get_regexes
from trufflehogregexes import regexes
Quickstart
from trufflehogregexes import regexes
# The 'regexes' variable is a list of dictionaries
print(f"Total regexes available: {len(regexes)}")
if regexes:
first_regex = regexes[0]
print(f"\nExample regex entry:")
print(f" ID: {first_regex.get('id')}")
print(f" Name: {first_regex.get('name')}")
print(f" Regex: {first_regex.get('regex')}")
print(f" Tags: {first_regex.get('tags')}")
# To actually use a regex, you'd compile and run it:
import re
test_string = "My private key is: AKIAIOSFODNN7EXAMPLE"
for r_entry in regexes:
pattern = r_entry.get('regex')
if pattern:
# Note: some regexes might require 're.DOTALL' or other flags
match = re.search(pattern, test_string)
if match:
print(f"\nMatch found for '{r_entry.get('name')}': {match.group(0)}")
break # Found one match for demonstration