Install & Compatibility
Where this runs
tested against v2.9.2 · 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
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.795s · 27.3MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 4.6s · import 0.719s · 28MB
25MB installed
● package 25MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
TosClientV2
✓ import tos
client = tos.TosClientV2(...)
✗ from tos import TosClient
The primary client class is `TosClientV2`, not `TosClient` from older versions or other SDKs.
TosClientError
✓ from tos.exceptions import TosClientError
Specific exception for client-side errors (e.g., invalid parameters, network issues).
TosServerError
✓ from tos.exceptions import TosServerError
Specific exception for server-side errors (e.g., HTTP status codes from TOS service).
This quickstart demonstrates how to initialize the `TosClientV2` using environment variables for authentication and endpoint configuration. It then performs a basic operation like listing buckets and checking for an object, including essential error handling for both client-side and server-side issues.
import os
import tos
from tos.exceptions import TosClientError, TosServerError
# Ensure environment variables are set for authentication
# os.environ['TOS_ACCESS_KEY'] = 'YOUR_ACCESS_KEY'
# os.environ['TOS_SECRET_KEY'] = 'YOUR_SECRET_KEY'
# os.environ['TOS_ENDPOINT'] = 'http://tos-cn-beijing.volces.com' # Example endpoint
# os.environ['TOS_REGION'] = 'cn-beijing' # Example region
ak = os.environ.get('TOS_ACCESS_KEY', '')
sk = os.environ.get('TOS_SECRET_KEY', '')
endpoint = os.environ.get('TOS_ENDPOINT', '')
region = os.environ.get('TOS_REGION', '')
bucket_name = 'your-example-bucket'
object_key = 'your-example-object'
client = None
try:
# Initialize TosClientV2 with credentials and endpoint
client = tos.TosClientV2(ak, sk, endpoint, region)
# Example: List buckets
print(f"Listing buckets for endpoint: {endpoint}")
response = client.list_buckets()
print("Buckets:")
for bucket in response.buckets:
print(f"- {bucket.name}")
# Example: Check if a specific object exists (simplified for quickstart)
try:
response = client.head_object(bucket_name, object_key)
print(f"Object '{object_key}' exists in bucket '{bucket_name}'.")
except TosServerError as e:
if e.status == 404:
print(f"Object '{object_key}' not found in bucket '{bucket_name}'.")
else:
raise # Re-raise other server errors
except TosClientError as e:
print(f"Client-side error: {e}")
except TosServerError as e:
print(f"Server-side error: Status {e.status}, Code {e.code}, Message: {e.message}")
except Exception as e:
print(f"An unexpected error occurred: {e}")
finally:
if client: # Ensure client is closed if it manages connections
pass # No explicit close method documented for TosClientV2 in examples, usually handled internally
Upgrade
Version history
2.9.2latest on PyPI · released Jun 3, 2026
Audit
Dependencies
Python 3.7+requiredRequired Python version for the SDK functionality.