WUP provides multiple anomaly detection methods to identify configuration drift, structural changes, and potential issues without requiring Playwright.
from wup.anomaly_detector import AnomalyDetector, YAMLAnomalyConfig
# Basic usage - scan YAML files for changes
detector = AnomalyDetector('./my-project')
results = detector.scan_directory('./my-project/config', '*.yaml')
detector.print_report(results)Compares file checksums to detect any changes.
from wup.anomaly_detector import AnomalyDetector, YAMLAnomalyConfig
config = YAMLAnomalyConfig(methods=['hash'])
detector = AnomalyDetector('./my-project', config)
# Scan specific file
result = detector.scan_file('config/database.yaml')Use case: Quick validation that files haven't changed unexpectedly. Performance: ~1ms per file
Deep comparison of YAML structure (keys, types, nesting).
config = YAMLAnomalyConfig(methods=['structure'])
detector = AnomalyDetector('./my-project', config)
results = detector.scan_directory('./config', '*.yaml')Detects:
- Added/removed keys
- Type changes (string → number)
- List length changes
- Nested structure changes
Use case: Detect configuration drift in Kubernetes manifests, Docker Compose files.
Analyzes Python source code structure.
config = YAMLAnomalyConfig(methods=['ast'])
detector = AnomalyDetector('./my-project', config)
results = detector.scan_directory('./src', '*.py')Detects:
- New/removed classes
- New/removed functions
- Import changes
- Method signature changes
Use case: API compatibility checking before deployment.
Use multiple methods for comprehensive analysis.
config = YAMLAnomalyConfig(
methods=['hash', 'structure', 'ast'],
strict_mode=True
)from wup.anomaly_detector import YAMLAnomalyConfig
config = YAMLAnomalyConfig(
enabled=True,
methods=['hash', 'structure'], # Detection methods to use
ignore_patterns=[ # Files to skip
'*.tmp',
'*.bak',
'.git/*',
'__pycache__/*',
'.venv/*',
'node_modules/*'
],
max_key_depth=5, # Max nesting level for structure analysis
max_file_size_kb=500, # Skip files larger than this
strict_mode=False # True = detect minor changes
)# Scan all YAML files
python -m wup.anomaly_detector ./my-project
# Scan specific pattern
python -m wup.anomaly_detector ./my-project --pattern "*.yml"
# Use specific methods
python -m wup.anomaly_detector ./my-project --methods hash,structure# Watch for changes every 5 seconds
python -m wup.anomaly_detector ./my-project --watch --interval 5
# Alert on critical changes only
python -m wup.anomaly_detector ./my-project --watch --severity criticalanomaly_detection:
enabled: true
methods:
- hash
- structure
watch_paths:
- "config/*.yaml"
- "deployments/*.yml"
ignore_patterns:
- "*.tmp"
- "*.local.yaml"
severity_threshold: medium # Only report medium+ severity
# Auto-actions on detection
on_detection:
- alert_slack
- create_ticket
- notify_dashboard| Level | Description | Example |
|---|---|---|
critical |
Breaking changes | Removed required key, syntax error |
high |
Significant changes | Type change, API removal |
medium |
Notable changes | New keys, structure changes |
low |
Minor changes | Whitespace, comments |
{
'detector': 'structure',
'file_path': './config/database.yaml',
'anomaly_type': 'drift',
'severity': 'high',
'message': 'Struktura YAML zmieniona (3 zmiany)',
'details': {
'diffs': [
{'path': 'database.host', 'change': 'key_removed', 'key': 'host'},
{'path': 'database.port', 'change': 'type_changed', 'old': 'str', 'new': 'int'}
],
'total_diffs': 3
},
'suggestions': [
"Sprawdź czy usunięcie klucza 'host' nie zepsuje integracji",
"Typ zmieniony w 'database.port' - może to wpłynąć na parsing"
],
'timestamp': 1714411200
}| Method | Speed | Memory | Best For |
|---|---|---|---|
| hash | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ | Quick validation |
| structure | ⭐⭐⭐⭐ | ⭐⭐⭐⭐ | Config drift detection |
| ast | ⭐⭐⭐ | ⭐⭐⭐ | Python code analysis |
| text | ⭐⭐ | ⭐⭐ | Detailed diff review |
- Use hash for CI/CD - Fast validation in pipelines
- Use structure for staging - Detect config drift before production
- Use ast for Python projects - API compatibility checking
- Combine methods for production monitoring
pip install pyyamlconfig = YAMLAnomalyConfig(
max_file_size_kb=100, # Reduce limit
max_key_depth=3 # Reduce depth
)config = YAMLAnomalyConfig(
strict_mode=False, # Relax detection
ignore_patterns=['*.local.yaml', '*.test.yaml']
)from wup.anomaly_detector import AnomalyResult
class CustomDetector:
def detect(self, file_path: Path) -> Optional[AnomalyResult]:
# Your custom detection logic
pass
detector = AnomalyDetector('./project')
detector.detectors['custom'] = CustomDetector()