GithubHelp home page GithubHelp logo

aliyun-openapi-python-sdk's Introduction

Alibaba Cloud Python Software Development Kit

中文文档

The Alibaba Cloud Python Software Development Kit (SDK) allows you to access Alibaba Cloud services such as Elastic Compute Service (ECS), Object Storage Service (OSS), and Resource Access Management (RAM). You can access Alibaba Cloud services without the need to handle API related tasks, such as signing and constructing your requests.

This document introduces how to obtain and call Alibaba Cloud Python SDK.

Prerequisites

  • To use Alibaba Cloud Python SDK, you must have an Alibaba Cloud account as well as an AccessKey.

    The AccessKey is required when initializing AcsClient. You can create an AccessKey in the Alibaba Cloud console. For more information, see Create an AccessKey.

    Note: To increase the security of your account, we recommend that you use the AccessKey of the RAM user to access Alibaba Cloud services.

  • To use Alibaba Cloud Python SDK to access the APIs of a product, you must first activate the product on the Alibaba Cloud console if required.

  • Alibaba Cloud Python SDK requires 2.6.x, 2.7.x, and Python 3.x.

Install Python SDK

Alibaba Cloud Python SDK supports Python 2.6.x, 2.7.x, and Python 3.x. Run python --version to check your version of Python.

You can install the Alibaba Cloud Python SDK using the following two methods. Regardless of which method and cloud service are used, the core library aliyun-python-sdk-core must be installed.

  • Install with pip

    Python SDK uses a common package management tool named pip. If pip is not installed, see the pip user guide to install pip.

    Run the following command to install the individual libraries of Alibaba Cloud services:

     # Install the core library
     pip install aliyun-python-sdk-core
     # Install the ECS management library
     pip install aliyun-python-sdk-ecs
     # Install the RDS management library
     pip install aliyun-python-sdk-rds

Note: If you are using Python 3.x, run the following command to install the core library:

>`pip install aliyun-python-sdk-core-v3`
  • Install from GitHub

    You can clone the source code to your local folder and then run setup.py install to install the SDK:

     git clone https://github.com/aliyun/aliyun-openapi-python-sdk.git
     # Install the core library
     cd aliyun-python-sdk-core
     python setup.py install
     # Install the ECS management library
     cd aliyun-python-sdk-ecs
     python setup.py install
    

Use Python SDK

  1. Import the required modules as follows:

    from aliyunsdkcore.client import AcsClient
    from aliyunsdkcore.acs_exception.exceptions import ClientException
    from aliyunsdkcore.acs_exception.exceptions import ServerException
    from aliyunsdkecs.request.v20140526 import DescribeInstancesRequest
    from aliyunsdkecs.request.v20140526 import StopInstanceRequest
  2. Initialize the AcsClient instance:

      client = AcsClient(
    	  "<access-key-id>", 
    	  "<access-key-secret>",
    	  "<region-id>"
      );

    where:

    • access-key-id is the Accesskey ID for your account.

    • access-key-secret is the AccessKey secret for your account.

    • region-id is the ID of the region where the service is called. For a list of region IDs, see Regions and zones.

    Note: The sequence of these parameters cannot be changed.

  3. Initialize a request and print response.

      #  Initialize a request and set parameters
      request = DescribeInstancesRequest.DescribeInstancesRequest()
      request.set_PageSize(10)
      # Print response
      response = client.do_action_with_exception(request)
      print response

    ##Code example

    The following example shows how to query a list of ECS instances in a specific region using DescribeInstances. Substitute the values for your-access-key-id, your-access-key-secret, and your-region-id.

      # -*- coding: utf8 -*-
    
      from aliyunsdkcore.client import AcsClient
      from aliyunsdkcore.acs_exception.exceptions import ClientException
      from aliyunsdkcore.acs_exception.exceptions import ServerException
      from aliyunsdkecs.request.v20140526 import DescribeInstancesRequest
      from aliyunsdkecs.request.v20140526 import StopInstanceRequest
    
      # Initialize AcsClient instance
      client = AcsClient(
    	  "<your-access-key-id>", 
    	  "<your-access-key-secret>",
    	  "<your-region-id>"
      );
    
      # Initialize a request and set parameters
      request = DescribeInstancesRequest.DescribeInstancesRequest()
      request.set_PageSize(10)
    
      # Print response
      response = client.do_action_with_exception(request)
      print response

aliyun-openapi-python-sdk's People

Contributors

danceiny avatar liyan2011 avatar malijiefoxmail avatar qingtang-sdk avatar suzaku avatar wuling0412 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.