Alibaba Cloud OSS SDK for Python v2
alibabacloud-oss-python-sdk-v2 is the v2 of the OSS SDK for the Python programming language
README in Chinese
About
- This Python SDK is based on the official APIs of Alibaba Cloud OSS.
- Alibaba Cloud Object Storage Service (OSS) is a cloud storage service provided by Alibaba Cloud, featuring massive capacity, security, a low cost, and high reliability.
- The OSS can store any type of files and therefore applies to various websites, development enterprises and developers.
- With this SDK, you can upload, download and manage data on any app anytime and anywhere conveniently.
Running Environment
- Python 3.8 or above.
Installing
Install the beta version through pip
$ pip install alibabacloud-oss-v2
Install from the unzipped installer package directly
$ sudo python setup.py install
Getting Started
List Bucket
import alibabacloud_oss_v2 as oss
def main():
region = "cn-hangzhou"
# Loading credentials values from the environment variables
credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()
# Using the SDK's default configuration
cfg = oss.config.load_default()
cfg.credentials_provider = credentials_provider
cfg.region = region
client = oss.Client(cfg)
# Create the Paginator for the ListBuckets operation
paginator = client.list_buckets_paginator()
# Iterate through the bucket pages
for page in paginator.iter_page(oss.ListBucketsRequest(
)
):
for o in page.buckets:
print(f'Bucket: {o.name}, {o.location}, {o.creation_date} {o.resource_group_id}')
if __name__ == "__main__":
main()
List Objects
import alibabacloud_oss_v2 as oss
def main():
region = "cn-hangzhou"
bucket_name = "your bucket name"
# Loading credentials values from the environment variables
credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()
# Using the SDK's default configuration
cfg = oss.config.load_default()
cfg.credentials_provider = credentials_provider
cfg.region = region
client = oss.Client(cfg)
# Create the Paginator for the ListObjectsV2 operation
paginator = client.list_objects_v2_paginator()
# Iterate through the object pages
for page in paginator.iter_page(oss.ListObjectsV2Request(
bucket=bucket_name
)
):
for o in page.contents:
print(f'Object: {o.key}, {o.size}, {o.last_modified}')
if __name__ == "__main__":
main()
Put Object
import alibabacloud_oss_v2 as oss
def main():
region = "cn-hangzhou"
bucket_name = "your bucket name"
object_name = "your object name"
local_file = "your local file path"
# Loading credentials values from the environment variables
credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()
# Using the SDK's default configuration
cfg = oss.config.load_default()
cfg.credentials_provider = credentials_provider
cfg.region = region
client = oss.Client(cfg)
with open(local_file, 'rb') as f:
result = client.put_object(oss.PutObjectRequest(
bucket=bucket_name,
key=object_name,
body=f,
))
print(f'put object successfully, ETag {result.etag}')
if __name__ == "__main__":
main()
Complete Example
More example projects can be found in the sample folder
Running Example
- Go to the sample code folder
sample。- Configure credentials values from the environment variables, like
export OSS_ACCESS_KEY_ID="your access key id",export OSS_ACCESS_KEY_SECRET="your access key secrect"- Take
list_buckets.pyas an example,runpython list_buckets.py --region cn-hangzhoucommand。
Resources
Developer Guide - Use this document to learn how to get started and use this sdk.
License
- Apache-2.0, see license file
Metadata
Release files for alibabacloud-oss-v2 1.4.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| alibabacloud_oss_v2-1.4.1-py3-none-any.whl | Python 3 | none | any | Details for alibabacloud_oss_v2-1.4.1-py3-none-any.whl |
Release files / alibabacloud_oss_v2-1.4.1-py3-none-any.whl
| Download URL | alibabacloud_oss_v2-1.4.1-py3-none-any.whl |
|---|---|
| Size | 377.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7d13702de8e5ffdcedbbe5a646e879570e392d04daba307b0d37422629a0425d
|
|
BLAKE2b-256 checksum How to use checksums |
91f925db81a42ae5e19a4a3064a9a10df608b23df15250a7e94799cf6f72d482
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.2
|
Security for alibabacloud-oss-v2 1.4.1
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.