Install the AI Guardrails API SDK for Python and configure credentials before making your first API call.
Prerequisites
Before you begin, ensure that you have:
Python 2.x or Python 3.x installed
pip installed on your server
To verify pip is available, run:
pip --versionIf pip is not installed, use the command for your Linux distribution:
| Distribution | Command |
|---|---|
| CentOS, Red Hat Enterprise Linux | yum -y install python3-pip |
| Ubuntu, Debian | apt-get -y install python3-pip |
| openSUSE, SUSE | zypper -n install python3-pip |
Install the SDK
Before installing the SDK packages, download the Extension.Uploader utility class and import it into your project.
Then install the SDK packages for your Python version.
Python 2.x
pip install aliyun-python-sdk-core==2.13.10
pip install -v aliyun-python-sdk-green==3.6.6
pip install oss2Python 3.x
pip install aliyun-python-sdk-core-v3==2.13.10
pip install -v aliyun-python-sdk-green==3.6.6
pip install oss2Configure environment variables
The SDK reads your AccessKey pair from environment variables to authenticate API calls. Store credentials in environment variables rather than hardcoding them in source code.
Never include your AccessKey ID or AccessKey secret directly in code or commit them to version control. Use environment variables or a secrets manager to keep credentials secure.
Set the following environment variables:
export ALIBABA_CLOUD_ACCESS_KEY_ID='<your-access-key-id>'
export ALIBABA_CLOUD_ACCESS_KEY_SECRET='<your-access-key-secret>'Replace the placeholders with your actual values:
| Placeholder | Description |
|---|---|
<your-access-key-id> | Your Alibaba Cloud AccessKey ID |
<your-access-key-secret> | Your Alibaba Cloud AccessKey secret |
For more information on managing credentials, see Configure credentials.