Skip to main content

Volcengine TOS SDK for Python

The TOS Python SDK enables Python developers to easily work with TOS(Tinder Object Storage) service in the volcengine. This document will show developers some basic examples about TOS bucket and object operation.

Install

Requirements

  • Python3

Quick Start

This section introduces how to create a bucket, upload/download/delete an object in TOS service through our SDK.

Create a TOS Client

You can interact with TOS service after initiating a TOSClient instance. The accesskey and secretkey of your account, endpoint and region are required as params.

import tos

ak = "your access key"
sk = "your secret key"
endpoint = "your endpoint"
region = "your region"
bucket_name = "your bucket name"
object_key = "your object key"
client = tos.TosClientV2(ak, sk, endpoint, region)     

Use VKE IRSA

After enabling VKE IRSA and associating an IAM role with the workload's ServiceAccount, pod-identity-webhook injects VOLCENGINE_OIDC_ROLE_TRN, VOLCENGINE_OIDC_TOKEN_FILE, and a read-only OIDC token file into the Pod. The application can then run without a long-lived AK/SK:

import tos

client = tos.TosClientV2(
    endpoint="https://tos-cn-beijing.volces.com",
    region="cn-beijing",
    credentials_provider=tos.OIDCCredentialsProvider(),
)

The provider exchanges the projected token through STS AssumeRoleWithOIDC and refreshes temporary credentials before they expire. Without the webhook, pass role_trn and oidc_token_file explicitly.

Use clients with fork

After a fork, the child rebuilds the SDK's default HTTP connection pools, bucket-type cache and DNS refresh state. OIDC credentials are fetched again on first use in the child.

Other credential providers and application callbacks need their own fork-safety guarantees.

Create a bucket

The bucket is a kind of unique namespace in TOS, which is a container to store data. This example shows you how to create a bucket.

import tos

ak = "your access key"
sk = "your secret key"
endpoint = "your endpoint"
region = "your region"
bucket_name = "your bucket name"
client = tos.TosClientV2(ak, sk, endpoint, region)
client.create_bucket(bucket_name)                            

Put Object

You can put your file as an object into your own bucket.

# call put_object to upload you data to the TOS                     
client.put_object(bucket_name, object_key, content="123")
assert resp.status_code == 200       

Get Object

You can download objects in the TOS bucket through our SDK.

# call get_object to download your data from your bucket
client.get_object(bucket_name, object_key)

Delete Object

Your can delete your objects in the bucket:

# call put_object to upload you data to the TOS  
resp = client.put_object(bucket_name, key_name, content="123")
assert resp.status_code == 200   
# call delete_object to delete an object in your bucket
resp = client.delete_object(bucket_name, key_name)
assert resp.status_code == 204

Security and privacy

This project takes security seriously. For vulnerability reporting and supported versions, see SECURITY.md

License

Apache License 2.0

Metadata

Release files for tos 2.9.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tos 2.9.3
File Size Uploaded
tos-2.9.3.tar.gz 179.4 kB Details

Release files / tos-2.9.3.tar.gz

Download URL tos-2.9.3.tar.gz
Size 179.4 kB
Tags Source
SHA-256 checksum
How to use checksums
fc048bd71f932c5c50b3098f3cb5303b856bee2b60dc5ae4b18ea4b34835e13c
BLAKE2b-256 checksum
How to use checksums
1233f680d45b8d1233596142b70c4e87ac892df00654f25ad3d5cf00455c3d2f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.7.7

Release history Release notifications | RSS feed

This release

2.9.3 This release

1 release file

2.9.2

1 release file

2.9.1

1 release file

2.9.0

1 release file

2.8.7

1 release file

2.8.6

1 release file

2.8.5

1 release file

2.8.4

1 release file

2.8.3

1 release file

2.8.1

1 release file

2.8.0

1 release file

2.7.2

1 release file

2.7.1

1 release file

2.7.0

1 release file

2.6.12

1 release file

2.6.11

1 release file

2.6.9

1 release file

2.6.8

1 release file

2.6.7

1 release file

2.6.6

1 release file

2.6.5

1 release file

2.6.4

1 release file

2.6.3

1 release file

2.6.2

1 release file

2.6.1

1 release file

2.6.0

1 release file

2.5.7

1 release file

2.5.6

1 release file

2.5.5

1 release file

2.5.4

1 release file

2.5.3

1 release file

2.5.2

1 release file

2.5.0

1 release file

2.4.2

1 release file

2.4.1

1 release file

2.3.4

1 release file

2.3.3

2 release files

2.3.2

1 release file

2.3.1

1 release file

2.3.0

1 release file

2.1.0

1 release file

1.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page