{"id":23239,"library":"aliyun-python-sdk-sts","title":"Aliyun STS SDK for Python","description":"The official Alibaba Cloud (Aliyun) STS (Security Token Service) SDK for Python. Version 3.1.3. Allows obtaining temporary security credentials (access keys) for accessing Alibaba Cloud resources. Release cadence is low, typically updated alongside the core SDK.","status":"active","version":"3.1.3","language":"python","source_language":"en","source_url":"https://github.com/aliyun/aliyun-openapi-python-sdk","tags":["alibaba","cloud","sts","security-token-service","sdk"],"install":[{"cmd":"pip install aliyun-python-sdk-sts","lang":"bash","label":"Install from PyPI"}],"dependencies":[{"reason":"Required for Alibaba Cloud SDK infrastructure; not automatically installed by this package.","package":"aliyun-python-sdk-core","optional":false}],"imports":[{"note":"Wrong import; the SDK uses the full request class.","wrong":"import sts","symbol":"StsRequest","correct":"from aliyunsdksts.request.v20150401 import AssumeRoleRequest"},{"note":"The client is from aliyunsdkcore, not from the sts package.","wrong":"from aliyunsdksts.client import AcsClient","symbol":"StsClient","correct":"from aliyunsdkcore.client import AcsClient"}],"quickstart":{"code":"from aliyunsdkcore.client import AcsClient\nfrom aliyunsdksts.request.v20150401 import AssumeRoleRequest\nimport json\n\nclient = AcsClient(\n    os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_ID', ''),\n    os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_SECRET', ''),\n    'cn-hangzhou'\n)\n\nrequest = AssumeRoleRequest()\nrequest.set_RoleArn('acs:ram::1234567890:role/ecsbackup')\nrequest.set_RoleSessionName('session-test')\nresponse = client.do_action_with_exception(request)\nprint(json.loads(response))","lang":"python","description":"Assume a role using STS to get temporary credentials."},"warnings":[{"fix":"Use AcsClient from aliyunsdkcore.client and request classes from aliyunsdksts.request","message":"In version 3.x, the base SDK was restructured. All request classes are now in aliyunsdk<service>.request. Do not use the old AliyunApiClient pattern.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Install both: pip install aliyun-python-sdk-core aliyun-python-sdk-sts","message":"The STS SDK does not install the core SDK automatically. If you only install aliyun-python-sdk-sts, you will get ImportError for AcsClient.","severity":"gotcha","affected_versions":"all"},{"fix":"Use client.do_action_with_exception(request) which returns a string.","message":"The older method client.do_action(request) (without _with_exception) is deprecated; it returns raw bytes without error handling.","severity":"deprecated","affected_versions":"<3.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Run: pip install aliyun-python-sdk-core","cause":"Missing dependency aliyun-python-sdk-core.","error":"ImportError: No module named 'aliyunsdkcore'"},{"fix":"Use: from aliyunsdksts.request.v20150401 import AssumeRoleRequest","cause":"Wrong import statement; trying to import the module instead of the request class.","error":"AttributeError: module 'aliyunsdksts' has no attribute 'request'"},{"fix":"Ensure RoleArn is set with the correct format: acs:ram::<account-id>:role/<role-name>","cause":"RoleArn parameter is missing or incorrectly formatted.","error":"aliyunsdkcore.exception.ServerException: HTTP Status: 404 Error: InvalidParameter.RoleArn"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}