Skip to main content
https://badge.fury.io/py/oss2.svg https://travis-ci.org/aliyun/aliyun-oss-python-sdk.svg?branch=master https://coveralls.io/repos/github/aliyun/aliyun-oss-python-sdk/badge.svg?branch=master

README of Chinese <https://github.com/aliyun/aliyun-oss-python-sdk/blob/master/README-CN.rst>

Overview

Alibaba Cloud Object Storage Python SDK 2.x. This version is not compatible with the previous version (Version 0.x). The package name is oss2 to avoid conflict with previous versions.

The SDK of this version is dependent on the third-party HTTP library requests and crcmod. Install the SDK following the methods below.

Note:

This version does not contain the osscmd command line tool.

Running environment

Python 2.6(not recommended),2.7,3.3(not recommended),3.4,3.5,3.6

Note:

Python 2.6 is not recommended because it is no longer supported by the Python core team. Do not use Python 3.3.0 or 3.3.1. Refer to Python Issue 16658.

Installing

Install the official release version through PIP (taking Linux as an example):

$ pip install oss2

You can also install the unzipped installer package directly:

$ sudo python setup.py install

Getting started

# -*- coding: utf-8 -*-

import oss2

endpoint = 'http://oss-cn-hangzhou.aliyuncs.com' # Suppose that your bucket is in the Hangzhou region.

auth = oss2.Auth('<Your AccessKeyID>', '<Your AccessKeySecret>')
bucket = oss2.Bucket(auth, endpoint, '<your bucket name>')

# The object key in the bucket is story.txt
key = 'story.txt'

# Upload
bucket.put_object(key, 'Ali Baba is a happy youth.')

# Download
bucket.get_object(key).read()

# Delete
bucket.delete_object(key)

# Traverse all objects in the bucket
for object_info in oss2.ObjectIterator(bucket):
    print(object_info.key)

For more examples, refer to the code under the “examples” directory.

Handling errors

The Python SDK interface will throw an exception in case of an error (see oss2.exceptions sub-module) unless otherwise specified. An example is provided below:

try:
    result = bucket.get_object(key)
    print(result.read())
except oss2.exceptions.NoSuchKey as e:
    print('{0} not found: http_status={1}, request_id={2}'.format(key, e.status, e.request_id))

Setup Logging

The following code can set the logging level of ‘oss2’.
import logging
logging.getLogger('oss2').setLevel(logging.WARNING)

Testing

First set the required AccessKeyId, AccessKeySecret, endpoint and bucket information for the test through environment variables (Do not use the bucket for the production environment). Take the Linux system for example:

$ export OSS_TEST_ACCESS_KEY_ID=<AccessKeyId>
$ export OSS_TEST_ACCESS_KEY_SECRET=<AccessKeySecret>
$ export OSS_TEST_ENDPOINT=<endpoint>
$ export OSS_TEST_BUCKET=<bucket>

$ export OSS_TEST_STS_ID=<AccessKeyId for testing STS>
$ export OSS_TEST_STS_KEY=<AccessKeySecret for testing STS>
$ export OSS_TEST_STS_ARN=<Role ARN for testing STS>

Run the test in the following method:

$ nosetests                          # First install nose

You can set environment variable to test auth v2:

$ export OSS_TEST_AUTH_VERSION=v2

More resources

Contacting us

License

Release files for oss2 2.19.1

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

Source distribution (sdist)

Source distribution for oss2 2.19.1
File Size Uploaded
oss2-2.19.1.tar.gz 298.8 kB Details

Release files / oss2-2.19.1.tar.gz

Download URL oss2-2.19.1.tar.gz
Size 298.8 kB
Tags Source
SHA-256 checksum
How to use checksums
a8ab9ee7eb99e88a7e1382edc6ea641d219d585a7e074e3776e9dec9473e59c1
BLAKE2b-256 checksum
How to use checksums
dfb5f2cb1950dda46ac2284d6c950489fdacd0e743c2d79a347924d3cc44b86f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.8.10

Release history Release notifications | RSS feed

This release

2.19.1 This release

1 release file

2.19.0

1 release file

2.18.6

1 release file

2.18.5

1 release file

2.18.4

1 release file

2.18.3

1 release file

2.18.2

1 release file

2.18.1

1 release file

2.18.0

1 release file

2.17.0

1 release file

2.16.0

1 release file

2.15.0

1 release file

2.14.0

1 release file

2.13.1

1 release file

2.13.0

1 release file

2.12.1

1 release file

2.12.0

1 release file

2.11.0

1 release file

2.10.0

1 release file

2.9.1

1 release file

2.9.0

1 release file

2.8.0

1 release file

2.7.0

2 release files

2.6.1

1 release file

2.6.0

1 release file

2.5.0

1 release file

2.4.0

1 release file

2.3.4

1 release file

2.3.3

1 release file

2.3.2

1 release file

2.3.1

1 release file

2.3.0

1 release file

2.2.3

1 release file

2.2.2

1 release file

2.2.1

1 release file

2.2.0

1 release file

2.1.1

1 release file

2.1.0

1 release file

2.0.6

1 release file

2.0.5

1 release file

2.0.4

1 release file

2.0.3

1 release file

2.0.2

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