Installation

Last Updated: Sep 30, 2017

Related resources:

Environment Requirements

This version of Python SDK is applicable to Python 2.6, 2.7, 3.3, 3.4 and 3.5. First, follow the instructions on python official website to install an appropriate version of Python.

After Python is installed:

  • Verify the Python version in Linux Shell:

    1. $ python -V
    2. Python 2.7.10

    If the preceding information is displayed, it means that you have successfully installed Python 2.7.10.

  • Verify the Python version in Windows CMD:

    1. C:\> python -V
    2. Python 2.7.10

    If the prerceding information is displayed, it means that you have successfully installed Python 2.7.10. If the system prompts “Not an internal or external command”, check the configuration Environment Variables > Path and add the Python installation path.

Install the SDK

  • Install the SDK via Pip

    1. pip install oss2

    Note: If Pip is not installed in your environment, see the Pip official website to install Pip.

  • Install via source code

    Download the SDK package of an appropriate version from github, decompress the package, and check whether there is a setup.py file under the directory:

    1. python setup.py install
  • Verification

    Input python in the command line and press Enter to verify the SDK version in Python environment:

    1. >>> import oss2
    2. >>> oss2.__version__
    3. '2.0.0'

    If the preceding information is displayed, it means that you have successfully installed the Python SDK of the specified version (Version 2.0.0 is used as an example here)

The oss2 library uses the crcmod module to calculate CRC. The crcmod will be installed automatically when oss2 is installed. Two methods are available for crcmod to calculate CRC: the C extension mode and the Python-only mode. The performance of the former is far better than the latter. For more information, see crcmod introduction.

To determine whether the crcmod C extension mode has been successfully installed, enter python in the command line and press Enter (in the Python environment, enter import crcmod._crcfunext and press Enter).

  • If ImportError: No module named crcmod._crcfunext is prompted, it indicates that the C extension mode is not successfully installed. The Python-only mode will be used for calculating the CRC.

    1. >>> import crcmod._crcfunext
    2. Traceback (most recent call last):
    3. File "<stdin>", line 1, in <module>
    4. ImportError: No module named crcmod._crcfunext
  • If no exception is reported after you enter import crcmod._crcfunext and press Enter, it indicates that the C extension mode has been successfully installed and the C extension mode will be used for calculating the CRC.

If the crcmod C extension mode is not successfully installed, we recommend that you disable CRC data verification. For how to disable the feature, see Initialization.

Uninstall the SDK

We recommend that you use Pip to uninstall the SDK:

  1. pip uninstall oss2

Sample project

The sample code for the Python SDK is under the examples directory.

Address: GitHub.

The sample includes the following content:

Sample files Sample content
object_basic.py Demonstrate object-related basic usage, including Upload, Download, List and Delete.
object_extra.py Demonstrate object-related advanced usage, such as Chinese, set Object Meta, Copy Object, and Append Upload.
upload.py Demonstrate advanced usage of Object Upload like resumable upload and multipart upload.
download.py Demonstrate Object Download usage, such as downloading objects, downloading by range and resumable download.
object_check.py Demonstrate usage for data verification during uploads/downloads, including MD5 and CRC.
object_progress.py Demonstrate usage of the progress bar feature, including the upload progress bar and the download progress bar.
object_callback.py Demonstrate Upload Callback usage.
object_post.py Demonstrate PostObject usage. The PostObject implementation is not dependent on the Python SDK.
sts.py Demonstrate STS usage, including getting the temporary user key for playing a role and using the temporary user key to access the OSS.
image.py Demonstrate Image Service usage.
bucket.py Demonstrate Bucket Management Operations usage, such as creating, deleting, and listing buckets.

Previous versions

This version of Python SDK is incompatible with the earlier version 0.4.2, and it does not contain the command line tool OSSCMD.

To download Python SDK and OSSCMD of the old versions, click here.

Thank you! We've received your feedback.