skip to navigation
skip to content


Aliyun OSS (Object Storage Service) SDK With Proxies Support

Alibaba Cloud OSS SDK for Python

.. image::
.. image::
.. image::

`README of Chinese <https:"" aliyun="" aliyun-oss-python-sdk="" blob="" master="" readme-cn.rst="">`_


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 <https:"" kennethreitz="" requests="">`_ and `crcmod`. Install the SDK following the methods below.


This version does not contain the `osscmd` command line tool.

Run environment

Python 2.6,2.7,3.3,3.4,3.5

.. note::

Do not use Python 3.3.0 or 3.3.1. Refer to `Python Issue 16658 <https:"" issue16658="">`_.

Installation method

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

.. code-block:: bash

$ pip install oss2

You can also install the unzipped installer package directly:

.. code-block:: bash

$ sudo python install

Quick use

.. code-block:: python

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

import oss2

endpoint = '' # 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

# Delete

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

For more examples, refer to the code under the "examples" directory.

Handle 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:

.. code-block:: python

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


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:

.. code-block:: bash

$ 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:

.. code-block:: bash

$ nosetests # First install nose

More usage
- `More examples can be found <https:"" aliyun="" aliyun-oss-python-sdk="" tree="" master="" examples="">`_.
- `Python SDK API documentation <http:"" en="" latest="">`_.
- `Official Python SDK documentation <https:"" document_detail="" 32026.html="">`_.

Contact us
- `Alibaba Cloud OSS official website <http:"">`_.
- `Alibaba Cloud OSS official forum <http:"">`_.
- `Alibaba Cloud OSS official documentation center <https:"" document_detail="" 32026.html="">`_.
- Alibaba Cloud official technical support: `Submit a ticket <https:"" #="" ticket="" createindex="">`_.

Code license
For the MIT license, see LICENSE object.
File Type Py Version Uploaded on Size
prox_oss2- (md5) Python Wheel 3.6 2017-06-17 43KB