Alibaba Cloud Log Service SDK for Python

raw JSON →
5.12.1 verified Fri May 01 auth: no python

Official Alibaba Cloud SDK for Log Service (SLS) API version 2020-12-30. Supports log ingestion, query, indexing, dashboards, and more. Current version 5.12.1 (released 2025-07-07). Release cadence is irregular, typically with minor updates monthly. Requires Python >=3.7.

pip install alibabacloud-sls20201230
error AttributeError: module 'alibabacloud_sls20201230' has no attribute 'Client'
cause Client is not imported correctly; must import from client module.
fix
from alibabacloud_sls20201230.client import Client
error SDKError: InvalidAccessKeySecret. Specified access key secret is not valid.
cause Access credentials are incorrect or not properly set via environment variables.
fix
Ensure ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET are set correctly.
error Exception: 'NoneType' object has no attribute 'total'
cause Response may be empty if project does not exist or endpoint is wrong.
fix
Check endpoint configuration and ensure project exists. Validate response before accessing fields.
error UnicodeEncodeError: 'ascii' codec can't encode characters
cause Python 2 compatibility issue; only relevant when using Python 2 (unsupported on >=5.x).
fix
Use Python >=3.7. For Python 2, stick to alibabacloud-sls20201230 <5.0.0.
breaking Version 4.x to 5.x drops support for Python 2.7. Requires Python >=3.7. All imports changed to snake_case packages.
fix Use from alibabacloud_sls20201230.client import Client instead of from aliyunsdksls.client import Client.
gotcha API endpoint must be specified for regions outside mainland China. Default endpoint (cn-hangzhou) may not work for international regions.
fix Set endpoint via client._endpoint = 'https://sls.ap-southeast-1.aliyuncs.com' or use region in credential.
deprecated The list_logstore method returns only 100 log stores by default. Pagination must be handled manually if more exist.
fix Use offset and size parameters in ListLogStoreRequest to paginate.

Initialize client with credentials and list projects.

import os
from alibabacloud_sls20201230.client import Client
from alibabacloud_sls20201230 import models
from alibabacloud_credentials.client import CredentialClient

credential = CredentialClient(
    access_key_id=os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_ID', ''),
    access_key_secret=os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_SECRET', ''),
)
client = Client(credential)

# List projects
req = models.ListProjectRequest()
resp = client.list_project(req)
print(resp.body.total)