This documentation provides detailed information about each module in the Darktrace SDK and how to use them.
from darktrace import DarktraceClient
# Initialize the client
client = DarktraceClient(
host="https://your-darktrace-instance",
public_token="YOUR_PUBLIC_TOKEN",
private_token="YOUR_PRIVATE_TOKEN",
debug=False, # Set to True for verbose output
verify_ssl=True # SSL verification enabled by default
)| Parameter | Type | Default | Description |
|---|---|---|---|
host |
str | required | The Darktrace instance hostname (e.g., 'https://example.darktrace.com') |
public_token |
str | required | Your Darktrace API public token |
private_token |
str | required | Your Darktrace API private token |
debug |
bool | False | Enable debug logging |
verify_ssl |
bool | True | Enable SSL certificate verification |
timeout |
int/float | None | Request timeout in seconds (None = no timeout) |
⚠️ BREAKING CHANGE: SSL verification default changed fromFalsetoTruein v0.9.0. If using self-signed certificates, you must either add them to your system trust store or setverify_ssl=Falseexplicitly.
The SDK now includes several reliability and security features:
- Connection Pooling: HTTP connections are pooled via
requests.Session()for better performance - Context Manager: Use
with DarktraceClient(...) as client:for proper resource cleanup - Automatic Retry: Transient failures (5xx, 429, connection errors) are retried up to 3 times with exponential backoff (3s, 6s, 12s)
- SSRF Protection: Dangerous URL schemes (
file://,ftp://,data://) are blocked; private IPs allowed
# Context manager usage (recommended)
with DarktraceClient(
host="https://your-darktrace-instance",
public_token="YOUR_PUBLIC_TOKEN",
private_token="YOUR_PRIVATE_TOKEN",
timeout=30 # Optional: 30 second timeout
) as client:
devices = client.devices.get()
# Connection automatically closed when exiting blockSSL certificate verification is enabled by default for secure connections. For development environments with self-signed certificates:
client = DarktraceClient(
host="https://your-darktrace-instance",
public_token="YOUR_PUBLIC_TOKEN",
private_token="YOUR_PRIVATE_TOKEN",
verify_ssl=False # Only for development/testing
)
⚠️ Warning: Disabling SSL verification is not recommended for production environments.
The Darktrace SDK provides access to all Darktrace API endpoints through the following modules:
- Advanced Search - Complex search operations across the Darktrace platform
- AI Analyst - AI Analyst incidents and investigations
- Antigena - Antigena actions and configurations
- Model Breaches - Model breach alerts and information
- Components - Darktrace component information
- CVEs - CVE information related to devices
- Details - Detailed information about specific entities
- Device Info - Detailed device information
- Devices - Device management and information
- Device Search - Search for devices with specific criteria
- Device Summary - Summarized device information
- Email - Darktrace Email security features
- Endpoint Details - Endpoint-specific information
- Enums - Enumeration values used in the Darktrace platform
- Filter Types - Available filter types for searches
- Intel Feed - Threat intelligence feed information
- Model Breach Comments - Comments on model breaches
- Metric Data - Time-series metric data
- Metrics - Available metrics and their information
- Models - Darktrace models and their configurations
- Network - Network information and statistics
- PCAPs - Packet capture functionality
- Similar Devices - Find devices similar to a given device
- Status - System status information
- Subnets - Subnet information and management
- Summary Statistics - Overall system statistics
- Tags - Tag management for devices and entities
The SDK handles authentication automatically using the provided public and private tokens. See Authentication for more details.
try:
devices = client.devices.get()
except Exception as e:
print(f"Error: {e}")Enable debug mode to see detailed API requests and responses:
client = DarktraceClient(
host="https://your-darktrace-instance",
public_token="YOUR_PUBLIC_TOKEN",
private_token="YOUR_PRIVATE_TOKEN",
debug=True # Enable debug output
)