Skip to main content

Alibaba Cloud OSS SDK for Python v2

GitHub version

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.py as an example,run python list_buckets.py --region cn-hangzhou command。

Resources

Developer Guide - Use this document to learn how to get started and use this sdk.

License

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

alibabacloud_oss_v2-1.4.0-py3-none-any.whl (360.2 kB view details)

Uploaded Python 3

File details

Details for the file alibabacloud_oss_v2-1.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for alibabacloud_oss_v2-1.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c0226aca0dfc59a3f12d895dabfc4e2af3c3a6f7136847418bb1bfd7e4ddcba9
MD5 685d7421e0dad892a0944c02844aadee
BLAKE2b-256 d09a9c9d891b3724dc8a907d7b74583833b3988226080b41d75b2c4200c9396b

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.4.0 This release

1 file

1.3.2

1 file

1.3.1

1 file

1.3.0

1 file

1.2.5

1 file

1.2.4

1 file

1.2.3

1 file

1.2.2

1 file

1.2.1

1 file

1.2.0

2 files

1.1.3

2 files

1.1.2

1 file

1.1.1

1 file

1.1.0

1 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