Registry / auth-security / alibabacloud-credentials

alibabacloud-credentials

JSON →
library1.0.12pypypi✓ verified 25d ago

The alibabacloud-credentials library is the core module for managing authentication credentials within the Alibaba Cloud Python SDK. It provides various credential providers (AccessKey, STS, RAM, EcsRamRole, OAuth, CloudSSO) and handles credential loading from environment variables, configuration files, and metadata services. The current version is 1.0.8, and it maintains a regular release cadence with several patches and minor features per year.

pip install alibabacloud-credentials
INSTALL
IMPORT
SIG · ALIBABACLOUD-CREDE
A
alibabacloud-credentials
auth-securitypythonv1.0.12
Install
5.7s avg
Import
Disk
32MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.0.12 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 32.7MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 5.7s · import 0.000s · 35MB
32MB installed
● package 32MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Config
from alibabacloud_credentials.models import Config
Used to configure credential providers.
DefaultCredentialsProvider
from alibabacloud_credentials.client import DefaultCredentialsProvider
The primary class for automatic credential resolution from various sources (env, config file, instance metadata, etc.).
AccessKeyCredential
from alibabacloud_credentials.client import AccessKeyCredential
Used for explicitly providing Access Key ID and Secret.

This quickstart demonstrates how to use the `DefaultCredentialsProvider` to automatically resolve and retrieve Alibaba Cloud credentials. It first initializes a `Config` object (which can be pre-configured or left empty for automatic resolution) and then creates a `DefaultCredentialsProvider`. It attempts to fetch and print the Access Key ID, Access Key Secret, and Security Token. For actual use, ensure environment variables like `ALIBABA_CLOUD_ACCESS_KEY_ID` and `ALIBABA_CLOUD_ACCESS_KEY_SECRET` are set, or a valid `.aliyun/config.json` file is present.

import os from alibabacloud_credentials.models import Config from alibabacloud_credentials.client import DefaultCredentialsProvider # Configure credentials - this provider will try to resolve credentials # from environment variables, config files, instance metadata service, etc. # You can explicitly set access_key_id, access_key_secret, security_token in Config # if you don't want automatic resolution. # For example: # config = Config( # type='access_key', # access_key_id=os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_ID', 'YOUR_AK_ID'), # access_key_secret=os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_SECRET', 'YOUR_AK_SECRET') # ) config = Config() provider = DefaultCredentialsProvider(config) try: access_key_id = provider.get_access_key_id() access_key_secret = provider.get_access_key_secret() security_token = provider.get_security_token() print(f"Access Key ID: {access_key_id}") print(f"Access Key Secret: {access_key_secret[:4]}...{access_key_secret[-4:]}") if security_token: print(f"Security Token: {security_token[:4]}...{security_token[-4:]}") except Exception as e: print(f"Error getting credentials: {e}") print("Please ensure ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables are set,") print("or a valid Alibaba Cloud configuration file exists.")
Debug
Known issues
breakingThe library now explicitly requires Python 3.7 or newer. Earlier versions (pre-1.0.6) might have worked with Python 3.6, but starting from v1.0.6, compatibility with Python versions older than 3.7 is no longer guaranteed and may lead to syntax errors (e.g., due to the walrus operator `:=`).
fix
Upgrade your Python environment to 3.7 or newer. If you must use an older Python, pin your `alibabacloud-credentials` version to `<1.0.6`, but be aware you will miss important bug fixes.
affects: <1.0.6
gotchaOlder versions (up to 1.0.5/1.0.6) contained bugs related to OAuth token refresh and saving, particularly when using `ChainableRamRoleArn` profiles or when a source profile was involved. This could lead to expired tokens not being refreshed or saved correctly, resulting in intermittent authentication failures.
fix
Upgrade to `alibabacloud-credentials` version `1.0.7` or newer to benefit from fixes that increase OAuth token refresh lead time and correctly update OAuth tokens even with source profiles.
affects: >=1.0.0, <1.0.7
gotchaIn versions prior to 1.0.2 (and pre-1.0rc3), attempts to load a non-existent `profile_name` in a configuration might not have raised an explicit error, potentially leading to silent failures or unexpected fallback behavior. From 1.0.2 onwards, attempting to use a non-existent profile name will correctly raise an error.
fix
Upgrade to `alibabacloud-credentials` version `1.0.2` or newer. Always ensure that the `profile_name` specified in your `Config` or `ALIBABA_CLOUD_PROFILE` environment variable corresponds to an existing profile in your `.aliyun/config.json`.
affects: <1.0.2
breakingThe `DefaultCredentialsProvider` constructor signature has changed. It no longer accepts a `Config` object as a positional argument, leading to a `TypeError` if instantiated with arguments. The constructor now expects no arguments beyond `self` (i.e., `DefaultCredentialsProvider()`).
fix
Instantiate `DefaultCredentialsProvider` without any arguments, for example: `provider = DefaultCredentialsProvider()`. Refer to the library's latest documentation for the correct method to configure credentials with this class.
affects: >=1.0.7
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'alibabacloud_credentials'
The 'alibabacloud_credentials' module is not installed or not properly installed.
fix
Ensure the module is installed by running: pip install alibabacloud-credentials
AttributeError: 'CredentialModel' object has no attribute 'provider_name'
An outdated version of the 'alibabacloud_credentials' package is being used, lacking the 'provider_name' attribute.
fix
Upgrade to the latest version by running: pip install --upgrade alibabacloud-credentials
AccessKeyId/AccessKeySecret is empty! run `aliyun configure` first
The AccessKey ID or AccessKey secret is not set in the configuration.
fix
Run the following commands to configure your credentials: aliyun configure set --profile <profileName> --access-key-id <yourAccessKeyId> --access-key-secret <yourAccessKeySecret>
the profile `<profileName>` does not exist
The specified credential profile does not exist in the configuration.
fix
Verify the available profiles by running: aliyun configure list
unknown profile <PROFILE_NAME>, run configure to check
The specified credential configuration does not exist in the configuration file.
fix
Run the following commands to check and create the credential configuration: aliyun configure list/get; aliyun configure set --profile <PROFILE_NAME> --access-key-id <yourAccessKeyId> --access-key-secret <yourAccessKeySecret>
Upgrade
Version history
1.0.12latest on PyPI · released Aug 18, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
52 hits · last 30 days
node
46
OpenAI (training)
1
Resources
alibabacloud-credentials — pip install alibabacloud-credentials · libregistry