- github project
- SDK API documentation: All interfaces and class details
- PyPi homepage
- Version iterations
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:
$ python -V
If the preceding information is displayed, it means that you have successfully installed Python 2.7.10.
Verify the Python version in Windows CMD:
C:\> python -V
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 via Pip
pip install oss2
Note: If Pip is not installed in your environment, refer to 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:
python setup.py install
pythonin the command line and press Enter to verify the SDK version in Python environment:
>>> import oss2
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 details, 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:
>>> import crcmod._crcfunext
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named crcmod._crcfunext
it indicates that the C extension mode is not successfully installed. The Python-only mode will be used for calculating the CRC. 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.
We recommend that you use Pip to uninstall the SDK:
pip uninstall oss2
The sample code for the Python SDK is under the examples directory.
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.|
|live_channel.py||Demonstrate Live Channel usage.|
|image.py||Demonstrate Image Service usage.|
|bucket.py||Demonstrate Bucket Management Operations usage, such as creating, deleting and listing buckets.|
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.