Registry / aws / bce-python-sdk

bce-python-sdk

JSON →
library0.9.76pypypi✓ verified 23d ago

The BCE Python SDK is the official software development kit for interacting with Baidu Cloud Engine services. It provides a convenient way for Python developers to integrate their applications with various Baidu AI Cloud products and services, such as object storage (BOS), virtual private cloud (VPC), and more. The current version is 0.9.69, and releases appear to be on an as-needed basis rather than a strict cadence, with the last update on PyPI on March 29, 2026.

pip install bce-python-sdk
INSTALL
IMPORT
SIG · BCE-PYTHON-SDK
B
bce-python-sdk
awspythonv0.9.76
Install
2.8s avg
Import
196ms
Disk
36MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.9.76 · 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.194s · 36.3MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.8s · import 0.198s · 37MB
36MB installed
● package 36MB
Code
Verified usage

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

BceCredentials
from baidubce.auth.bce_credentials import BceCredentials
BceClientConfiguration
from baidubce.bce_client_configuration import BceClientConfiguration
BosClient
from baidubce.services.bos import bos_client
Example for Object Storage (BOS) client. Replace 'bos' with the specific service you need (e.g., 'vpc', 'iam').

This quickstart demonstrates how to initialize a client for Baidu Object Storage (BOS) using your Access Key (AK), Secret Key (SK), and a service endpoint. It shows the basic steps to configure the client and make a sample API call (listing buckets). Remember to replace 'YOUR_AK' and 'YOUR_SK' with your actual credentials, ideally from environment variables, and choose the correct endpoint for your service and region.

import os from baidubce.auth.bce_credentials import BceCredentials from baidubce.bce_client_configuration import BceClientConfiguration from baidubce.services.bos import bos_client from baidubce.exception import BceHttpClientError # Configure your Baidu Cloud credentials and endpoint # It's highly recommended to use environment variables for AK/SK ACCESS_KEY_ID = os.environ.get('BCE_ACCESS_KEY_ID', 'YOUR_AK') SECRET_ACCESS_KEY = os.environ.get('BCE_SECRET_ACCESS_KEY', 'YOUR_SK') BOS_ENDPOINT = os.environ.get('BCE_BOS_ENDPOINT', 'http://bj.bcebos.com') # Example: Beijing region for BOS if __name__ == '__main__': if ACCESS_KEY_ID == 'YOUR_AK' or SECRET_ACCESS_KEY == 'YOUR_SK': print("Please set BCE_ACCESS_KEY_ID and BCE_SECRET_ACCESS_KEY environment variables.") else: try: # Initialize client configuration config = BceClientConfiguration( credentials=BceCredentials(access_key_id=ACCESS_KEY_ID, secret_access_key=SECRET_ACCESS_KEY), endpoint=BOS_ENDPOINT ) # Create a BOS client client = bos_client.BosClient(config) # Example: List buckets (replace with actual service calls) response = client.list_buckets() print("Successfully connected to BOS. Buckets found:") for bucket in response.body.buckets: print(f"- {bucket.name}") except BceHttpClientError as e: print(f"An HTTP error occurred: {e}") except Exception as e: print(f"An unexpected error occurred: {e}")
Debug
Known issues
deprecatedThe SDK officially supports Python 2.7, but Python 2.7 reached End-of-Life in 2020. Running new projects or production environments on Python 2.7 is highly discouraged due to security vulnerabilities and lack of community support. The `future` dependency is also noted to be incompatible with Python 3.13.
fix
Migrate to Python 3.3 or higher. Ensure your environment uses a supported Python 3 version.
affects: <=0.9.69 (and likely future 2.x compatible versions)
gotchaEach Baidu Cloud service (e.g., BOS, VPC, BCC) and region has a specific endpoint. Using an incorrect endpoint will result in connection errors or incorrect service interaction.
fix
Always refer to the official Baidu AI Cloud documentation for the correct endpoint URL for your specific service and the region you are operating in (e.g., `bj.bcebos.com` for BOS in Beijing).
affects: All versions
gotchaAccess Key ID (AK) and Secret Access Key (SK) provide full programmatic access to your Baidu Cloud resources. Exposing them in source code, committing them to version control, or storing them insecurely can lead to unauthorized access and significant security risks.
fix
Store AK/SK securely, preferably using environment variables (as shown in quickstart), a dedicated secrets management service, or IAM roles if running on Baidu Cloud infrastructure. Never hardcode them in your application.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'baidubce'
The `bce-python-sdk` package or one of its submodules is not installed in the Python environment, or the environment where the code is run does not have access to the installed package.
fix
Install the SDK using pip: `pip install bce-python-sdk`
BceHttpClientError: Exception when calling api: %s
This error indicates a general failure during an API call to a Baidu Cloud service, often due to incorrect credentials, invalid request parameters, network issues, or a service-side problem.
fix
Catch the `BceHttpClientError` and inspect the exception object for detailed error messages, status codes, and request IDs to diagnose the underlying cause, then verify your access keys, secret keys, endpoint, and request parameters. Example: 
```python
from baidubce.exception import BceHttpClientError
try:
    # Your SDK API call here
    pass
except BceHttpClientError as e:
    print(f"API call failed: {e}")
    # Further inspect e.error_code, e.status_code, e.request_id
```
AttributeError: 'BosClient' object has no attribute 'some_method'
You are attempting to call a method or access an attribute that does not exist on the `BosClient` (or another client object from the SDK), possibly due to a typo in the method name or using a method from an incorrect client.
fix
Review the official `bce-python-sdk` documentation for the specific client (e.g., `BosClient`) to ensure the method name and its parameters are correct. Use `dir(client_object)` in an interactive Python session to inspect available attributes and methods. 
```python
from baidubce.services.bos.bos_client import BosClient
# ... client configuration ...
bos_client = BosClient(config)
# Incorrect method name, assuming 'list_bucket' should be 'list_buckets'
try:
    bos_client.list_bucket() 
except AttributeError as e:
    print(f"Error: {e}. Check the method name.")
# Correct fix:
bos_client.list_buckets()
```
KeyError: 'some_key'
When processing a dictionary response from an API call, you are trying to access a key that is not present in the dictionary, often because the API response structure differs from what was expected.
fix
Safely access dictionary keys using the `.get()` method with a default value, or check for key existence using the `in` operator, or wrap the access in a `try-except KeyError` block. 
```python
response = {'status': 'success', 'data': {'item_id': '123'}}

# Using .get() method
item_name = response.get('data', {}).get('item_name', 'N/A')
print(f"Item Name: {item_name}") # Output: Item Name: N/A

# Using try-except block
try:
    item_description = response['data']['item_description']
except KeyError:
    item_description = 'Description not available'
print(f"Item Description: {item_description}") # Output: Item Description: Description not available
```
authentication failed
This general message indicates that the provided Baidu Cloud authentication credentials (Access Key ID and Secret Access Key) are incorrect, expired, or lack the necessary permissions for the requested operation.
fix
Verify that your Access Key ID and Secret Access Key are correct and active in your Baidu AI Cloud console. Ensure the credentials have the required permissions for the specific service and API calls you are making. Also, confirm that the region endpoint is correctly configured.
Upgrade
Version history
0.9.76latest on PyPI · released Jul 24, 2026
Audit
Dependencies
pycryptodome>=3.8.0requiredRequired for cryptographic operations, likely for request signing and security.
future>=0.6.0requiredProvides Python 2 and 3 compatibility utilities, enabling the SDK to run on both environments.
six>=1.4.0requiredPython 2 and 3 compatibility utilities.
Agent activity
34 hits · last 30 days
node
32
OpenAI (training)
1
Resources
bce-python-sdk — pip install bce-python-sdk · libregistry