Installation

Last Updated: Nov 09, 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. Firstly, follow the instructions on python official website to install an appropriate version of Python.

Once 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 preceding 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 by Pip

    1. pip install oss2

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

  • Install by source code

    Download the SDK package of an appropriate version from github, decompress the package, and check whether the setup.py file is 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 is 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 C extension mode is better than the Python-only mode. 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 is then 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 once you enter import crcmod._crcfunext and press Enter, it indicates that the C extension mode has been successfully installed and the C extension mode is used for calculating the CRC.

If the crcmod C extension mode is not successfully installed, we recommend that you disable CRC data verification. For more information on 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 previous versions of Python SDK and OSSCMD, click here.

Thank you! We've received your feedback.