Python-SDK Help Guide
Precondition
This article aims to help you quickly get the Baidu AI Cloud Python SDK and start calling.
Precondition
Before development, make sure the following prerequisites are ready:
- The Python SDK toolkit supports running under Python 2.7.
-
Verification **AK/SK**: AK/SK parameters must be passed in for SDK authentication, and the Access Key and Secret Key can be obtained at Security Authentication Page.
You can interact with Baidu AI Cloud by two means, including authentication method and anonymous method. For authentication method, you need to verify the identity of a request sender by using Access Key Id / Secret Access Key encryption method. Access Key Id (AK) is used to identify users, and Secret Access Key (SK) is a key used by users to encrypt authentication string and by Baidu AI Cloud to verify the authentication string, where SK must be confidential, which can only be known by users and Baidu AI Cloud.
Install SDK Package
Download the Python SDK compression toolkit at Baidu AI Cloud Official Website. Execute the following command to install the SDK package:
python setup.py install
SDK's directory structure
baidubce
├── auth // Public privilege directory
├── http // Http request module
├── services // Service public directory
│ └── bos // Take object storage BOS as an example, BOS directory
│ ├──bos_client.py // BOS client entry class
│ ├──bos_handle.py // HTTP reponse manipulation function
│ ├──canned_acl.py // Constant required for privilege control
│ └──storage_class.py // Store type definition module
├── bce_base_client.py // Base class of BCE client entry class
├── bce_client_configuration.py // Configuration for BOS-specific HttpClient
├── bce_response.py // Request class of BCE client
├── exception.py // Exception class of BCE's client
├── protocol.py // Network protocol definition
├── region.py // Region processing module
├── retry_policy.py // Public configuration class of BCE service
└── utils.py // BCE's utility tool class
Use Python SDK
3 main steps to call the Python SDK:
- Create and initialize xxxClient. Baidu AI Cloud Service is configured with a detailed Python SDK help guide, please see the product guide for details.
- Create an API request and set parameters.
- Initiate a request and handle a response or exception.