Help Center > > Developer Guide> Python> Getting Started

Getting Started

Updated at: Oct 09, 2019 GMT+08:00

Welcome to use HUAWEI CLOUD developer tools (Python SDK). Python SDK allows you to easily access cloud services using codes.

This tutorial describes how to install and use Python SDK and provides examples to help you quickly get started.

The supported Python SDK is developed based on the Python OpenStack SDK.

Prerequisites

  1. You have obtained a cloud platform account and provisioned all required services.
  2. You have installed Python, pip, and git. Python SDK is applicable to Python 2.7.10 to 2.7.15 and 3.4 to 3.7.

SDK Acquisition and Installation

If the pip is used for installation, run the following command:

pip install huaweicloud-sdk-python

How to Use

Set parameters, create connections, and invoke the SDK to access the service API. For details about the parameters, see Table 1.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# -*- coding:utf-8 -*-
from openstack import connection

# create connection
username = "replace-with-your-username" # username
password = "replace-with-your-password" # user password
projectId = "replace-with-your-projectId"    # project ID
userDomainId = "replace-with-your-domainId"  # account ID
auth_url = "https://iam.example.com/v3"    # endpoint url
conn = connection.Connection(auth_url=auth_url,
                             user_domain_id=userDomainId,
                             project_id=projectId,
                             username=username,
                             password=password)

# set parameters
limit = 5

# define function for listing servers
def list_servers():
    # get server list with params
    servers = conn.compute.servers(limit=limit)
    # iterate servers list
    for server in servers:
        print(server)

# visit API
list_servers()
Table 1 Parameter description

Parameter

Description

Example Value

auth_url

Specifies the endpoint of the IAM service.

example in https://iam.example.com/v3, example indicates the domain name of the cloud platform. For details about the parameter, see here.

https://iam.cn-north-1.myhuaweicloud.com/v3

projectId

Specifies the project ID. For details about how to obtain the project ID, see How Can I Obtain domain_name, project_name, and project_id?.

None

userDomainId

Specifies the account ID. For details about how to obtain the account ID, see How Can I Obtain domain_name, project_name, and project_id?.

None

Did you find this page helpful?

Submit successfully!

Thank you for your feedback. Your feedback helps make our documentation better.

Failed to submit the feedback. Please try again later.

Which of the following issues have you encountered?







Please complete at least one feedback item.

Content most length 200 character

Content is empty.

OK Cancel