Getting Started with SDCClient
Follow the steps below to install and instantiate the Sysdig Python client library and scripts.
Python version 3.6 or above
pipversion 1.3 or above
pipis installed as part of the Python package for versions 2.7 and later.
Sysdig API token
Retrieve the Sysdig API Token
When using the Sysdig API with custom scripts or applications, an API security token (specific to each team) must be supplied.
Log in to Sysdig Monitor or Sysdig Secure and select Settings.
Select User Profile.
The Sysdig Monitor or Sysdig Secure API token is displayed (depending on which interface and team you logged in to).
Copy the token for use, or click the Reset Token button to generate a new one.
When reset, the previous token issued will immediately become invalid and you will need to make appropriate changes to your programs or scripts.
Install the Python Client
The library and example scripts are available in the Sysdig GitHub repository.
Install the Sysdig Python client (sdcclient) using one of the following methods:
Use the Pip Command
Install the client by using pip:
pip install sdcclient
Identify Your API Server
Check the drop-down to verify the API URL you should use in the client installation script.
The default region is US East and the URL is
For the On-Premises Sysdig platform installations, you need to use the
IP where your Sysdig API server is running.
To do so, set the following environment variables before running your Python scripts:
If you are using a self-signed certificate, set following variable:
Disable the SSL verification only if you don’t have a valid certificate.
Alternatively, you can specify the additional arguments in your Python scripts as you instantiate the SDC client:
client = SdMonitorClient(api_token, sdc_url='https://<YOUR-API-SERVER-HOSTNAME-OR-IP>', ssl_verify=False)
SDCClient supports the environment variables for
Open the terminal and set the
NO_PROXY environment variables:
export HTTPS_PROXY="http://myproxy.domain.com:8080" export NO_PROXY="127.0.0.1,localhost,.myinternal.domain.com"
Alternatively, you can add the following setting to your Python scripts as folllows.
import os os.environ['HTTPS_PROXY'] = 'http://myproxy.domain.com:8080' os.environ['NO_PROXY'] = '127.0.0.1,localhost,.myinternal.domain.com'
Instantiate the Library Classes
The library exports two classes,
which are used to connect to the Sysdig Monitor/Secure back end and
execute actions. (For backwards compatibility purposes, a third class
SdcClient is exported which is an alias of
They can be instantiated as follows:
from sdcclient import SdMonitorClient api_token ="MY_API_TOKEN" # # Instantiate the Sysdig Monitor client # client = SdMonitorClient(api_token)
Once instantiated, all the methods documented in the Python Script Library can be called on the object.
Every method in the
SdMonitorClient/SdSecureClient classes returns a
list with two entries. The first one is a boolean value indicating if
the call was successful. The second entry depends on the result:
If the call was successful, it’s a dictionary reflecting the json returned by the underlying REST call
If the call failed, it’s a string describing the error
For an example on how to parse the output, see get_data_simple.py
Using Logs for Learning Purposes
If your goal is to interact with the REST API directly, you can use the Python client library to understand the REST interactions by logging the actions it takes. This is useful because full documentation of the REST API has not yet been created; it also provides a complete example of known working operations.
Use or modify an example, or write a new script against the Python
Log the HTTP requests made by the script.
To log all the requests made by your script in significant detail, add to your script:
import logging import httplib httplib.HTTPConnection.debuglevel = 1 logging.basicConfig() # you need to initialize logging, otherwise you will not see anything from requests logging.getLogger().setLevel(logging.DEBUG) requests_log = logging.getLogger("requests.packages.urllib3") requests_log.setLevel(logging.DEBUG) requests_log.propagate = True
Then run as normal.
Explore the script library and function list.
Explore the sample Python scripts provided.
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.