介绍
腾讯云COSV5Python SDK, 目前可以支持Python2.6与Python2.7。
安装指南
使用pip安装
pip install -U cos-python-sdk-v5
手动安装:
python setup.py install
使用方法
使用python sdk,参照https://github.com/tencentyun/cos-python-sdk-v5/blob/master/qcloud_cos/demo.py
cos最新可用地域,参照https://www.qcloud.com/document/product/436/6224
# 设置用户属性, 包括secret_id, secret_key, region
secret_id = 'xxxxxxxx' # 替换为用户的secret_id
secret_key = 'xxxxxxx' # 替换为用户的secret_key
region = 'ap-beiging-1' # 替换为用户的region
token = '' # 使用临时秘钥需要传入Token,默认为空,可不填
config = CosConfig(Region=region, Secret_id=secret_id, Secret_key=secret_key, Token=token) #获取配置对象
client = CosS3Client(config) #获取客户端对象
############################################################################
# 文件操作 #
############################################################################
# 1. 上传单个文件
response = client.put_object(
Bucket='test01-123456789',
Body='TY'*1024*512*file_size,
Key=file_name,
CacheControl='no-cache',
ContentDisposition='download.txt'
)
# 2. 下载单个文件
response = client.get_object(
Bucket='test01-123456789',
Key=file_name,
)
# 3. 获取文件属性
response = client.head_object(
Bucket='test01-123456789',
Key=file_name
)
# 4. 删除单个文件
response = client.delete_object(
Bucket='test01-123456789',
Key=file_name
)
# 5. 创建分片上传
response = client.create_multipart_upload(
Bucket='test01-123456789',
Key='multipartfile.txt',
)
uploadid = get_id_from_xml(response.text)
# 6. 删除分片上传
response = client.abort_multipart_upload(
Bucket='test01-123456789',
Key='multipartfile.txt',
UploadId=uploadid
)
# 7. 再次创建分片上传
response = client.create_multipart_upload(
Bucket='test01-123456789',
Key='multipartfile.txt',
)
uploadid = response['UploadId']
# 8. 上传分片
response = client.upload_part(
Bucket='test01-123456789',
Key='multipartfile.txt',
UploadId=uploadid,
PartNumber=1,
Body='A'*1024*1024*4
)
etag = response['ETag']
# 9. 列出分片
response = clieent.list_parts(
Bucket='test01-123456789',
Key='mutilpartfile.txt',
UploadId=uploadid
)
lst = response['Part'] # list_parts最大数量为1000
# 10. 完成分片上传
response = client.complete_multipart_upload(
Bucket='test01-123456789',
Key='multipartfile.txt',
UploadId=uploadid,
MultipartUpload={'Part': lst} # 超过1000个分块,请本地保存分块信息,再complete
)
############################################################################
# Bucket操作 #
############################################################################
# 1. 创建Bucket
response = client.create_bucket(
Bucket='test02-123456789',
ACL='public-read'
)
# 2. 删除Bucket
response = client.delete_bucket(
Bucket='test02-123456789'
)
# 3. 获取文件列表
response = client.list_objects(
Bucket='test01-123456789'
)
Metadata
Release files for cos-python-sdk-v5-logging 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cos-python-sdk-v5-logging-1.0.0.tar.gz | 18.9 kB | Without provenance | Details for cos-python-sdk-v5-logging-1.0.0.tar.gz |
Release files / cos-python-sdk-v5-logging-1.0.0.tar.gz
| Download URL | cos-python-sdk-v5-logging-1.0.0.tar.gz |
|---|---|
| Size | 18.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ee73c9fd1190eb1533195577d84eeb20134e7d6c44f55bd7c561c57200827637
|
|
BLAKE2b-256 checksum How to use checksums |
4a01ef1a31eab2be21111b92db07233c6f04c4d09ae04fd37d0da20615bbee3a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for cos-python-sdk-v5-logging 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.