Sysdig Platform Python Client
sdcclient is the official Python client for the Sysdig Platform APIs (Monitor and Secure). It provides an easy-to-use interface to interact with Sysdig's REST APIs for tasks such as metric extraction, alert management, and user/team administration. The current version is 0.19.0, and releases generally follow the development of the Sysdig platform, with updates for new API features and bug fixes.
Common errors
-
Error: SYSDIG_API_TOKEN environment variable not set.
cause The Sysdig API token was not provided to the client constructor and the `SYSDIG_API_TOKEN` environment variable is missing.fixExport your Sysdig API token: `export SYSDIG_API_TOKEN='YOUR_TOKEN_HERE'` or pass it directly: `client = SdMonitorClient('YOUR_TOKEN_HERE')`. -
Failed to get user info: status code 401
cause The provided Sysdig API token is invalid or expired, resulting in an unauthorized access error.fixVerify your Sysdig API token. Obtain a new one from the Sysdig Monitor/Secure settings page if necessary. -
requests.exceptions.SSLError: ('CERTIFICATE_VERIFY_FAILED', ...)cause This usually occurs in on-premises installations with self-signed SSL certificates when `ssl_verify` is set to `True` (the default).fixSet `SDC_SSL_VERIFY='false'` as an environment variable or pass `ssl_verify=False` to the client constructor. Ensure you understand the security implications of disabling SSL verification.
Warnings
- gotcha The `SdcClient` class is an alias for `SdMonitorClient` for backward compatibility. While it still works, new code should explicitly use `SdMonitorClient` for Sysdig Monitor interactions and `SdSecureClient` for Sysdig Secure interactions to improve clarity and future-proof your code.
- gotcha Sysdig API methods return a tuple: `[boolean_success_status, result_data_or_error_string]`. Always check the boolean status before attempting to process the second element, as it will contain an error message on failure.
- gotcha For on-premises Sysdig installations, you must specify the API server URL and potentially disable SSL verification. This can be done via environment variables (`SDC_URL`, `SDC_SSL_VERIFY`) or directly in the client constructor.
Install
-
pip install sdcclient
Imports
- SdMonitorClient
from sdcclient import SdMonitorClient
- SdSecureClient
from sdcclient import SdSecureClient
- SdcClient
from sdcclient import SdcClient
Quickstart
import os
from sdcclient import SdMonitorClient
# It's recommended to store your API token in an environment variable for security.
# export SYSDIG_API_TOKEN='YOUR_SYSDIG_API_TOKEN'
# export SDC_URL='https://app.sysdig.com'
api_token = os.environ.get('SYSDIG_API_TOKEN', '')
sdc_url = os.environ.get('SDC_URL', 'https://app.sysdig.com') # Default SaaS URL
if not api_token:
print("Error: SYSDIG_API_TOKEN environment variable not set.")
exit(1)
# Instantiate the Sysdig Monitor client
client = SdMonitorClient(api_token, sdc_url=sdc_url)
# Example: Get current user information
ok, res = client.get_user_info()
if ok:
print("Successfully connected to Sysdig Monitor.")
print(f"User Info: {res}")
else:
print(f"Failed to get user info: {res}")