├── .gitignore ├── .travis.yml ├── CHANGELOG.rst ├── LICENSE ├── MANIFEST.in ├── QcloudApi ├── __init__.py ├── common │ ├── __init__.py │ ├── api_exception.py │ ├── request.py │ └── sign.py ├── modules │ ├── __init__.py │ ├── account.py │ ├── apigateway.py │ ├── athena.py │ ├── base.py │ ├── batch.py │ ├── bgpip.py │ ├── bill.py │ ├── bm.py │ ├── bmeip.py │ ├── bmlb.py │ ├── bmvpc.py │ ├── cbs.py │ ├── ccr.py │ ├── ccs.py │ ├── cdb.py │ ├── cdn.py │ ├── cloudaudit.py │ ├── cmem.py │ ├── cns.py │ ├── cvm.py │ ├── dc.py │ ├── dfw.py │ ├── eip.py │ ├── emr.py │ ├── feecenter.py │ ├── image.py │ ├── lb.py │ ├── live.py │ ├── market.py │ ├── monitor.py │ ├── partners.py │ ├── redis.py │ ├── scaling.py │ ├── scf.py │ ├── sec.py │ ├── snapshot.py │ ├── sts.py │ ├── tbaas.py │ ├── tdsql.py │ ├── tmt.py │ ├── trade.py │ ├── vod.py │ ├── vpc.py │ ├── wenzhi.py │ └── yunsou.py └── qcloudapi.py ├── README.md ├── README.rst ├── setup.cfg ├── setup.py ├── tests ├── __init__.py ├── demo.py ├── functional │ ├── __init__.py │ └── test_cvm.py ├── integration │ ├── ckafka │ │ └── test_list_instance.py │ └── cvm │ │ └── test_describe_instances.py └── unit │ ├── __init__.py │ ├── common │ └── test_sign.py │ └── modules │ ├── __init__.py │ └── test_basic.py └── tox.ini /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | 3 | # twine 4 | dist/ 5 | 6 | # tox 7 | .tox/ 8 | qcloudapi_sdk_python.egg-info/ 9 | 10 | # pytest, pytest-cov 11 | .cache/ 12 | .coverage 13 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | 3 | matrix: 4 | include: 5 | - language: python 6 | python: "2.7" 7 | env: TOXENV=py27 8 | 9 | - language: python 10 | python: "3.5" 11 | env: TOXENV=py35 12 | 13 | - language: python 14 | python: "3.6" 15 | env: TOXENV=py36 16 | 17 | install: 18 | - pip install --upgrade tox 19 | 20 | script: tox -r 21 | 22 | after_success: 23 | - tox -r -ecoveralls 24 | -------------------------------------------------------------------------------- /CHANGELOG.rst: -------------------------------------------------------------------------------- 1 | ========= 2 | CHANGELOG 3 | ========= 4 | 5 | latest (now) 6 | ============ 7 | 8 | 2.0.15 (2018-06-15) 9 | =================== 10 | 11 | * dynamic module support: Now user can call any product's API which runs on \*.api.qcloud.com even its module is not listed in SDK. 12 | 13 | 2.0.14 (2018-04-20) 14 | =================== 15 | 16 | * add dc module 17 | 18 | 2.0.13 (2018-04-16) 19 | =================== 20 | 21 | * add ccr module 22 | 23 | 2.0.12 (2018-03-02) 24 | =================== 25 | 26 | * add sts module 27 | * add emr module 28 | * add athena module 29 | * add tbaas module 30 | * add partners module 31 | 32 | 2.0.11 33 | ====== 34 | 35 | * add tmt module 36 | * add apigateway, batch, cloudaudit, scf module 37 | 38 | 2.0.10 39 | ====== 40 | 41 | 2017-11-27 42 | 43 | * fix bmlb, cns, feecenter module import error 44 | 45 | 2.0.9 46 | ===== 47 | 48 | 2017-10-30 49 | 50 | * add bgpip module 51 | 52 | history 53 | ======= 54 | 55 | * [2017/9/11] 增加Bmeip和Bmvpc模块 56 | * [2017/8/28] 业务接口的数组参数或者Object参数,支持以Json方式传入,可参考demo.py 57 | * [2017/8/21] 兼容python2和python3版本;支持pip安装使用 58 | * [2017/8/8] 增加Cns模块 59 | * [2017/8/7] 增加Feecenter模块 60 | * [2017/7/31] 增加Bmlb模块 61 | * [2017/7/12] 回滚:不默认传Version参数 62 | * [2017/5/24] 增加Ccs模块 63 | * [2017/5/19]设置接口默认Version: Cvm模块新版本API已经上线,通过是否传Version区分新旧版本。SDK默认调用新接口,因此需要增加Version的默认设置。 CvmAPI接口介绍见:https://www.qcloud.com/document/api/213/569 64 | * [2017/3/1] 增加对HmacSHA1和HmacSHA256签名算法兼容的支持 65 | * [2016/7/15] 增加Tdsql模块 66 | * [2016/7/6] 添加Cmem模块 67 | * [2016/5/24] 添加Cbs、Snapshot和Scaling模块 68 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 1999-2017 Tencent Ltd. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include README.rst 2 | include LICENSE 3 | recursive-include QcloudApi * 4 | -------------------------------------------------------------------------------- /QcloudApi/__init__.py: -------------------------------------------------------------------------------- 1 | __version__ = '2.0.15' 2 | -------------------------------------------------------------------------------- /QcloudApi/common/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QcloudApi/qcloudapi-sdk-python/9b097e4f4089cb6432ada7593999fab92f31fb43/QcloudApi/common/__init__.py -------------------------------------------------------------------------------- /QcloudApi/common/api_exception.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | 4 | class ApiExceptionBase(Exception): 5 | """ 6 | @type message: string 7 | @param message: error describe 8 | """ 9 | def __init__(self, message): 10 | self.message = message 11 | 12 | def get_info(self): 13 | return 'Error Message: %s\n' % (self.message) 14 | 15 | def __str__(self): 16 | return "ApiExceptionBase %s" % (self.get_info()) 17 | 18 | 19 | class ApiClientParamException(ApiExceptionBase): 20 | def __init__(self, message): 21 | ApiExceptionBase.__init__(self, message) 22 | 23 | def __str__(self): 24 | return "ApiClientException %s" % (self.get_info()) 25 | 26 | 27 | class ApiClientNetworkException(ApiExceptionBase): 28 | """ @note: client network exception 29 | """ 30 | def __init__(self, message): 31 | ApiExceptionBase.__init__(self, message) 32 | 33 | def __str__(self): 34 | return "ApiClientNetworkException %s" % (self.get_info()) 35 | 36 | 37 | class ApiServerNetworkException(ApiExceptionBase): 38 | """ @note: api server exception 39 | """ 40 | def __init__(self, status=200, header=None, data=""): 41 | if header is None: 42 | header = {} 43 | self.status = status 44 | self.header = header 45 | self.data = data 46 | 47 | def __str__(self): 48 | headers = "\n".join("%s: %s" % (k, v) for k, v in self.header.items()) 49 | return ("ApiServerNetworkException Status: %s\nHeader: %s\nData: %s\n" 50 | % (self.status, headers, self.data)) 51 | -------------------------------------------------------------------------------- /QcloudApi/common/request.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | import os 5 | import socket 6 | try: 7 | from http.client import HTTPConnection, BadStatusLine, HTTPSConnection 8 | from urllib.parse import urlparse 9 | except ImportError: 10 | from httplib import HTTPConnection, BadStatusLine, HTTPSConnection 11 | from urlparse import urlparse 12 | 13 | from .api_exception import ApiClientNetworkException, ApiClientParamException 14 | 15 | 16 | class MyHTTPSConnection(HTTPSConnection): 17 | def __init__(self, host, port=None): 18 | self.has_proxy = False 19 | self.request_host = host 20 | https_proxy = (os.environ.get('https_proxy') 21 | or os.environ.get('HTTPS_PROXY')) 22 | if https_proxy: 23 | url = urlparse(https_proxy) 24 | if not url.hostname: 25 | url = urlparse('https://' + https_proxy) 26 | host = url.hostname 27 | port = url.port 28 | self.has_proxy = True 29 | HTTPSConnection.__init__(self, host, port) 30 | self.request_length = 0 31 | 32 | def send(self, astr): 33 | HTTPSConnection.send(self, astr) 34 | self.request_length += len(astr) 35 | 36 | def request(self, method, url, body=None, headers={}): 37 | self.request_length = 0 38 | if self.has_proxy: 39 | self.set_tunnel(self.request_host, 443) 40 | HTTPSConnection.request(self, method, url, body, headers) 41 | 42 | 43 | class ApiRequest(object): 44 | def __init__(self, host, req_timeout=90, debug=False): 45 | self.conn = MyHTTPSConnection(host) 46 | self.req_timeout = req_timeout 47 | self.keep_alive = False 48 | self.debug = debug 49 | self.request_size = 0 50 | self.response_size = 0 51 | 52 | def set_req_timeout(self, req_timeout): 53 | self.req_timeout = req_timeout 54 | 55 | def is_keep_alive(self): 56 | return self.keep_alive 57 | 58 | def set_debug(self, debug): 59 | self.debug = debug 60 | 61 | def send_request(self, req_inter): 62 | try: 63 | if self.debug: 64 | print("SendRequest %s" % req_inter) 65 | if req_inter.method == 'GET': 66 | req_inter_url = '%s?%s' % (req_inter.uri, req_inter.data) 67 | self.conn.request(req_inter.method, req_inter_url, 68 | None, req_inter.header) 69 | elif req_inter.method == 'POST': 70 | self.conn.request(req_inter.method, req_inter.uri, 71 | req_inter.data, req_inter.header) 72 | else: 73 | raise ApiClientParamException( 74 | 'Method only support (GET, POST)') 75 | 76 | self.conn.sock.settimeout(self.req_timeout) 77 | self.conn.sock.setsockopt(socket.IPPROTO_TCP, 78 | socket.TCP_NODELAY, 1) 79 | try: 80 | http_resp = self.conn.getresponse() 81 | except BadStatusLine: 82 | # open another connection when keep-alive timeout 83 | # httplib will not handle keep-alive timeout, 84 | # so we must handle it ourself 85 | if self.debug: 86 | print("keep-alive timeout, reopen connection") 87 | self.conn.close() 88 | 89 | self.conn.request(req_inter.method, req_inter.uri, 90 | req_inter.data, req_inter.header) 91 | self.conn.sock.settimeout(self.req_timeout) 92 | self.conn.sock.setsockopt(socket.IPPROTO_TCP, 93 | socket.TCP_NODELAY, 1) 94 | http_resp = self.conn.getresponse() 95 | headers = dict(http_resp.getheaders()) 96 | resp_inter = ResponseInternal(status=http_resp.status, 97 | header=headers, 98 | data=http_resp.read()) 99 | self.request_size = self.conn.request_length 100 | self.response_size = len(resp_inter.data) 101 | if not self.is_keep_alive(): 102 | self.conn.close() 103 | if self.debug: 104 | print(("GetResponse %s" % resp_inter)) 105 | return resp_inter 106 | except Exception as e: 107 | self.conn.close() 108 | raise ApiClientNetworkException(str(e)) 109 | 110 | 111 | class RequestInternal(object): 112 | def __init__(self, host="", method="", uri="", header=None, data=""): 113 | if header is None: 114 | header = {} 115 | self.host = host 116 | self.method = method 117 | self.uri = uri 118 | self.header = header 119 | self.data = data 120 | 121 | def __str__(self): 122 | headers = "\n".join("%s: %s" % (k, v) for k, v in self.header.items()) 123 | return ("Host: %s\nMethod: %s\nUri: %s\nHeader: %s\nData: %s\n" 124 | % (self.host, self.method, self.uri, headers, self.data)) 125 | 126 | 127 | class ResponseInternal(object): 128 | def __init__(self, status=0, header=None, data=""): 129 | if header is None: 130 | header = {} 131 | self.status = status 132 | self.header = header 133 | self.data = data 134 | 135 | def __str__(self): 136 | headers = "\n".join("%s: %s" % (k, v) for k, v in self.header.items()) 137 | return ("Status: %s\nHeader: %s\nData: %s\n" 138 | % (self.status, headers, self.data)) 139 | -------------------------------------------------------------------------------- /QcloudApi/common/sign.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import binascii 4 | import hashlib 5 | import hmac 6 | import sys 7 | 8 | 9 | class Sign(object): 10 | def __init__(self, secretId, secretKey): 11 | self.secretId = secretId 12 | self.secretKey = secretKey 13 | if sys.version_info[0] > 2: 14 | self.Py2 = False 15 | self.secretKey = bytes(self.secretKey, 'utf-8') 16 | else: 17 | self.Py2 = True 18 | 19 | def make(self, requestHost, requestUri, params, 20 | method='POST', sign_method='HmacSHA1'): 21 | p = {} 22 | for k in params: 23 | if method == 'POST' and str(params[k])[0:1] == '@': 24 | continue 25 | p[k.replace('_', '.')] = params[k] 26 | ps = '&'.join('%s=%s' % (k, p[k]) for k in sorted(p)) 27 | 28 | msg = '%s%s%s?%s' % (method.upper(), requestHost, requestUri, ps) 29 | if not self.Py2: 30 | msg = bytes(msg, 'utf-8') 31 | 32 | if sign_method == 'HmacSHA256': 33 | digestmod = hashlib.sha256 34 | else: 35 | digestmod = hashlib.sha1 36 | 37 | hashed = hmac.new(self.secretKey, msg, digestmod) 38 | base64 = binascii.b2a_base64(hashed.digest())[:-1] 39 | if not self.Py2: 40 | base64 = base64.decode() 41 | 42 | return base64 43 | -------------------------------------------------------------------------------- /QcloudApi/modules/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QcloudApi/qcloudapi-sdk-python/9b097e4f4089cb6432ada7593999fab92f31fb43/QcloudApi/modules/__init__.py -------------------------------------------------------------------------------- /QcloudApi/modules/account.py: -------------------------------------------------------------------------------- 1 | # Copyright 1999-2017 Tencent Ltd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from QcloudApi.modules import base 16 | 17 | 18 | class Account(base.Base): 19 | requestHost = 'account.api.qcloud.com' 20 | -------------------------------------------------------------------------------- /QcloudApi/modules/apigateway.py: -------------------------------------------------------------------------------- 1 | # Copyright 1999-2017 Tencent Ltd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from QcloudApi.modules import base 16 | 17 | 18 | class APIGateway(base.Base): 19 | requestHost = 'apigateway.api.qcloud.com' 20 | -------------------------------------------------------------------------------- /QcloudApi/modules/athena.py: -------------------------------------------------------------------------------- 1 | # Copyright 1999-2018 Tencent Ltd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from QcloudApi.modules import base 16 | 17 | 18 | class Athena(base.Base): 19 | """Financial Intelligent Customer Service. 20 | 21 | document: https://cloud.tencent.com/document/product/671 22 | """ 23 | requestHost = 'athena.api.qcloud.com' 24 | -------------------------------------------------------------------------------- /QcloudApi/modules/base.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # 3 | # Copyright 1999-2017 Tencent Ltd. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | import copy 18 | import time 19 | import random 20 | import sys 21 | import os 22 | import warnings 23 | 24 | try: 25 | from urllib.parse import urlencode 26 | except ImportError: 27 | from urllib import urlencode 28 | 29 | import QcloudApi 30 | from QcloudApi.common.api_exception import ApiClientParamException 31 | from QcloudApi.common.api_exception import ApiServerNetworkException 32 | from QcloudApi.common.request import ApiRequest 33 | from QcloudApi.common.request import RequestInternal 34 | from QcloudApi.common.sign import Sign 35 | 36 | warnings.filterwarnings("ignore") 37 | 38 | 39 | class Base(object): 40 | requestHost = '' 41 | requestUri = '/v2/index.php' 42 | _params = {} 43 | version = 'SDK_PYTHON_%s' % QcloudApi.__version__ 44 | 45 | def __init__(self, config): 46 | self.secretId = config['secretId'] 47 | self.secretKey = config['secretKey'] 48 | self.defaultRegion = config.get('Region', '') 49 | self.Version = config.get('Version', '') 50 | self.method = config.get('method', 'GET').upper() 51 | self.sign_method = config.get('SignatureMethod', 'HmacSHA1') 52 | self.requestHost = self.requestHost or config.get("endpoint") 53 | self.apiRequest = ApiRequest(self.requestHost) 54 | self.Token = config.get('Token', '') 55 | 56 | def set_req_timeout(self, req_timeout): 57 | self.apiRequest.set_req_timeout(req_timeout) 58 | 59 | def open_debug(self): 60 | self.apiRequest.set_debug(True) 61 | 62 | def close_debug(self): 63 | self.apiRequest.set_debug(False) 64 | 65 | def _build_header(self, req): 66 | if self.apiRequest.is_keep_alive(): 67 | req.header["Connection"] = "Keep-Alive" 68 | if req.method == 'POST': 69 | req.header["Content-Type"] = "application/x-www-form-urlencoded" 70 | 71 | def _fix_params(self, params): 72 | if not isinstance(params, (dict,)): 73 | return params 74 | return self._format_params(None, params) 75 | 76 | def _format_params(self, prefix, params): 77 | d = {} 78 | if params is None: 79 | return d 80 | 81 | if not isinstance(params, (tuple, list, dict)): 82 | d[prefix] = params 83 | return d 84 | 85 | if isinstance(params, (list, tuple)): 86 | for idx, item in enumerate(params): 87 | if prefix: 88 | key = "{0}.{1}".format(prefix, idx) 89 | else: 90 | key = "{0}".format(idx) 91 | d.update(self._format_params(key, item)) 92 | return d 93 | 94 | if isinstance(params, dict): 95 | for k, v in params.items(): 96 | if prefix: 97 | key = '{0}.{1}'.format(prefix, k) 98 | else: 99 | key = '{0}'.format(k) 100 | d.update(self._format_params(key, v)) 101 | return d 102 | 103 | raise ApiClientParamException('some params type error') 104 | 105 | def _build_req_inter(self, action, params, req_inter): 106 | _params = copy.deepcopy(self._fix_params(params)) 107 | _params['Action'] = action[0].upper() + action[1:] 108 | _params['RequestClient'] = self.version 109 | 110 | if ('Region' not in _params and self.defaultRegion != ''): 111 | _params['Region'] = self.defaultRegion 112 | 113 | if ('Version' not in _params and self.Version != ''): 114 | _params['Version'] = self.Version 115 | 116 | if ('Token' not in _params and self.Token != ''): 117 | _params['Token'] = self.Token 118 | 119 | if ('SecretId' not in _params): 120 | _params['SecretId'] = self.secretId 121 | 122 | if ('Nonce' not in _params): 123 | _params['Nonce'] = random.randint(1, sys.maxsize) 124 | 125 | if ('Timestamp' not in _params): 126 | _params['Timestamp'] = int(time.time()) 127 | 128 | if ('SignatureMethod' in _params): 129 | self.sign_method = _params['SignatureMethod'] 130 | else: 131 | _params['SignatureMethod'] = self.sign_method 132 | 133 | sign = Sign(self.secretId, self.secretKey) 134 | _params['Signature'] = sign.make( 135 | req_inter.host, req_inter.uri, _params, 136 | req_inter.method, self.sign_method) 137 | 138 | req_inter.data = urlencode(_params) 139 | 140 | self._build_header(req_inter) 141 | 142 | def _check_status(self, resp_inter): 143 | if resp_inter.status != 200: 144 | raise ApiServerNetworkException( 145 | resp_inter.status, resp_inter.header, resp_inter.data) 146 | 147 | def generateUrl(self, action, params): 148 | req_inter = RequestInternal( 149 | self.requestHost, self.method, self.requestUri) 150 | self._build_req_inter(action, params, req_inter) 151 | url = 'https://%s%s' % (req_inter.host, req_inter.uri) 152 | if (req_inter.method == 'GET'): 153 | url += '?' + req_inter.data 154 | return url 155 | 156 | def call(self, action, params, files={}): 157 | req_inter = RequestInternal( 158 | self.requestHost, self.method, self.requestUri) 159 | self._build_req_inter(action, params, req_inter) 160 | resp_inter = self.apiRequest.send_request(req_inter) 161 | self._check_status(resp_inter) 162 | return resp_inter.data 163 | -------------------------------------------------------------------------------- /QcloudApi/modules/batch.py: -------------------------------------------------------------------------------- 1 | # Copyright 1999-2017 Tencent Ltd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from QcloudApi.modules import base 16 | 17 | 18 | class Batch(base.Base): 19 | requestHost = 'batch.api.qcloud.com' 20 | -------------------------------------------------------------------------------- /QcloudApi/modules/bgpip.py: -------------------------------------------------------------------------------- 1 | # Copyright 1999-2017 Tencent Ltd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from QcloudApi.modules import base 16 | 17 | 18 | class Bgpip(base.Base): 19 | requestHost = 'bgpip.api.qcloud.com' 20 | -------------------------------------------------------------------------------- /QcloudApi/modules/bill.py: -------------------------------------------------------------------------------- 1 | # Copyright 1999-2017 Tencent Ltd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from QcloudApi.modules import base 16 | 17 | 18 | class Bill(base.Base): 19 | requestHost = 'bill.api.qcloud.com' 20 | -------------------------------------------------------------------------------- /QcloudApi/modules/bm.py: -------------------------------------------------------------------------------- 1 | # Copyright 1999-2017 Tencent Ltd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from QcloudApi.modules import base 16 | 17 | 18 | class Bm(base.Base): 19 | requestHost = 'bm.api.qcloud.com' 20 | -------------------------------------------------------------------------------- /QcloudApi/modules/bmeip.py: -------------------------------------------------------------------------------- 1 | # Copyright 1999-2017 Tencent Ltd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from QcloudApi.modules import base 16 | 17 | 18 | class Bmeip(base.Base): 19 | requestHost = 'bmeip.api.qcloud.com' 20 | -------------------------------------------------------------------------------- /QcloudApi/modules/bmlb.py: -------------------------------------------------------------------------------- 1 | # Copyright 1999-2017 Tencent Ltd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from QcloudApi.modules import base 16 | 17 | 18 | class Bmlb(base.Base): 19 | requestHost = 'bmlb.api.qcloud.com' 20 | -------------------------------------------------------------------------------- /QcloudApi/modules/bmvpc.py: -------------------------------------------------------------------------------- 1 | # Copyright 1999-2017 Tencent Ltd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from QcloudApi.modules import base 16 | 17 | 18 | class Bmvpc(base.Base): 19 | requestHost = 'bmvpc.api.qcloud.com' 20 | -------------------------------------------------------------------------------- /QcloudApi/modules/cbs.py: -------------------------------------------------------------------------------- 1 | # Copyright 1999-2017 Tencent Ltd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from QcloudApi.modules import base 16 | 17 | 18 | class Cbs(base.Base): 19 | requestHost = 'cbs.api.qcloud.com' 20 | -------------------------------------------------------------------------------- /QcloudApi/modules/ccr.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018 Tencent Ltd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from QcloudApi.modules import base 16 | 17 | 18 | class Ccr(base.Base): 19 | """Cloud Container Repository 20 | 21 | document: https://cloud.tencent.com/document/product/457/9427 22 | """ 23 | requestHost = 'ccr.api.qcloud.com' 24 | -------------------------------------------------------------------------------- /QcloudApi/modules/ccs.py: -------------------------------------------------------------------------------- 1 | # Copyright 1999-2017 Tencent Ltd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from QcloudApi.modules import base 16 | 17 | 18 | class Ccs(base.Base): 19 | requestHost = 'ccs.api.qcloud.com' 20 | -------------------------------------------------------------------------------- /QcloudApi/modules/cdb.py: -------------------------------------------------------------------------------- 1 | # Copyright 1999-2017 Tencent Ltd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from QcloudApi.modules import base 16 | 17 | 18 | class Cdb(base.Base): 19 | requestHost = 'cdb.api.qcloud.com' 20 | -------------------------------------------------------------------------------- /QcloudApi/modules/cdn.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Copyright 1999-2017 Tencent Ltd. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | import hashlib 17 | import os 18 | 19 | from QcloudApi.modules import base 20 | 21 | 22 | class Cdn(base.Base): 23 | requestHost = 'cdn.api.qcloud.com' 24 | 25 | def UploadCdnEntity(self, params): 26 | action = 'UploadCdnEntity' 27 | if params.get('entityFile') is None: 28 | raise ValueError('entityFile can not be empty.') 29 | if os.path.isfile(params['entityFile']) is False: 30 | raise ValueError('entityFile is not exist.') 31 | 32 | file = params.pop('entityFile') 33 | if 'entityFileMd5' not in params: 34 | content = open(file, 'rb').read() 35 | params['entityFileMd5'] = hashlib.md5(content).hexdigest() 36 | 37 | files = { 38 | 'entityFile': open(file, 'rb') 39 | } 40 | 41 | return self.call(action, params, files) 42 | -------------------------------------------------------------------------------- /QcloudApi/modules/cloudaudit.py: -------------------------------------------------------------------------------- 1 | # Copyright 1999-2017 Tencent Ltd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from QcloudApi.modules import base 16 | 17 | 18 | class CloudAudit(base.Base): 19 | requestHost = 'cloudaudit.api.qcloud.com' 20 | -------------------------------------------------------------------------------- /QcloudApi/modules/cmem.py: -------------------------------------------------------------------------------- 1 | # Copyright 1999-2017 Tencent Ltd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from QcloudApi.modules import base 16 | 17 | 18 | class Cmem(base.Base): 19 | requestHost = 'cmem.api.qcloud.com' 20 | -------------------------------------------------------------------------------- /QcloudApi/modules/cns.py: -------------------------------------------------------------------------------- 1 | # Copyright 1999-2017 Tencent Ltd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from QcloudApi.modules import base 16 | 17 | 18 | class Cns(base.Base): 19 | requestHost = 'cns.api.qcloud.com' 20 | -------------------------------------------------------------------------------- /QcloudApi/modules/cvm.py: -------------------------------------------------------------------------------- 1 | # Copyright 1999-2017 Tencent Ltd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from QcloudApi.modules import base 16 | 17 | 18 | class Cvm(base.Base): 19 | requestHost = 'cvm.api.qcloud.com' 20 | -------------------------------------------------------------------------------- /QcloudApi/modules/dc.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Copyright (c) 2018 Tencent Ltd. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | from QcloudApi.modules import base 17 | 18 | 19 | class Dc(base.Base): 20 | """Tencent Cloud Direct Connect 21 | 22 | document: https://cloud.tencent.com/document/product/216/1711 23 | """ 24 | requestHost = 'dc.api.qcloud.com' 25 | -------------------------------------------------------------------------------- /QcloudApi/modules/dfw.py: -------------------------------------------------------------------------------- 1 | # Copyright 1999-2017 Tencent Ltd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from QcloudApi.modules import base 16 | 17 | 18 | class Dfw(base.Base): 19 | requestHost = 'dfw.api.qcloud.com' 20 | -------------------------------------------------------------------------------- /QcloudApi/modules/eip.py: -------------------------------------------------------------------------------- 1 | # Copyright 1999-2017 Tencent Ltd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from QcloudApi.modules import base 16 | 17 | 18 | class Eip(base.Base): 19 | requestHost = 'eip.api.qcloud.com' 20 | -------------------------------------------------------------------------------- /QcloudApi/modules/emr.py: -------------------------------------------------------------------------------- 1 | # Copyright 1999-2018 Tencent Ltd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from QcloudApi.modules import base 16 | 17 | 18 | class Emr(base.Base): 19 | """Elastic Map Reduce. 20 | 21 | document: https://cloud.tencent.com/document/product/589 22 | """ 23 | requestHost = 'emr.api.qcloud.com' 24 | -------------------------------------------------------------------------------- /QcloudApi/modules/feecenter.py: -------------------------------------------------------------------------------- 1 | # Copyright 1999-2017 Tencent Ltd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from QcloudApi.modules import base 16 | 17 | 18 | class Feecenter(base.Base): 19 | requestHost = 'feecenter.api.qcloud.com' 20 | -------------------------------------------------------------------------------- /QcloudApi/modules/image.py: -------------------------------------------------------------------------------- 1 | # Copyright 1999-2017 Tencent Ltd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from QcloudApi.modules import base 16 | 17 | 18 | class Image(base.Base): 19 | requestHost = 'image.api.qcloud.com' 20 | -------------------------------------------------------------------------------- /QcloudApi/modules/lb.py: -------------------------------------------------------------------------------- 1 | # Copyright 1999-2017 Tencent Ltd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from QcloudApi.modules import base 16 | 17 | 18 | class Lb(base.Base): 19 | requestHost = 'lb.api.qcloud.com' 20 | -------------------------------------------------------------------------------- /QcloudApi/modules/live.py: -------------------------------------------------------------------------------- 1 | # Copyright 1999-2017 Tencent Ltd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from QcloudApi.modules import base 16 | 17 | 18 | class Live(base.Base): 19 | requestHost = 'live.api.qcloud.com' 20 | -------------------------------------------------------------------------------- /QcloudApi/modules/market.py: -------------------------------------------------------------------------------- 1 | # Copyright 1999-2017 Tencent Ltd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from QcloudApi.modules import base 16 | 17 | 18 | class Market(base.Base): 19 | requestHost = 'market.api.qcloud.com' 20 | -------------------------------------------------------------------------------- /QcloudApi/modules/monitor.py: -------------------------------------------------------------------------------- 1 | # Copyright 1999-2017 Tencent Ltd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from QcloudApi.modules import base 16 | 17 | 18 | class Monitor(base.Base): 19 | requestHost = 'monitor.api.qcloud.com' 20 | -------------------------------------------------------------------------------- /QcloudApi/modules/partners.py: -------------------------------------------------------------------------------- 1 | # Copyright 1999-2017 Tencent Ltd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from QcloudApi.modules import base 16 | 17 | 18 | class Partners(base.Base): 19 | requestHost = 'partners.api.qcloud.com' 20 | -------------------------------------------------------------------------------- /QcloudApi/modules/redis.py: -------------------------------------------------------------------------------- 1 | # Copyright 1999-2017 Tencent Ltd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from QcloudApi.modules import base 16 | 17 | 18 | class Redis(base.Base): 19 | requestHost = 'redis.api.qcloud.com' 20 | -------------------------------------------------------------------------------- /QcloudApi/modules/scaling.py: -------------------------------------------------------------------------------- 1 | # Copyright 1999-2017 Tencent Ltd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from QcloudApi.modules import base 16 | 17 | 18 | class Scaling(base.Base): 19 | requestHost = 'scaling.api.qcloud.com' 20 | -------------------------------------------------------------------------------- /QcloudApi/modules/scf.py: -------------------------------------------------------------------------------- 1 | # Copyright 1999-2017 Tencent Ltd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from QcloudApi.modules import base 16 | 17 | 18 | class Scf(base.Base): 19 | """Serverless Cloud Function.""" 20 | 21 | requestHost = 'scf.api.qcloud.com' 22 | -------------------------------------------------------------------------------- /QcloudApi/modules/sec.py: -------------------------------------------------------------------------------- 1 | # Copyright 1999-2017 Tencent Ltd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from QcloudApi.modules import base 16 | 17 | 18 | class Sec(base.Base): 19 | requestHost = 'csec.api.qcloud.com' 20 | -------------------------------------------------------------------------------- /QcloudApi/modules/snapshot.py: -------------------------------------------------------------------------------- 1 | # Copyright 1999-2017 Tencent Ltd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from QcloudApi.modules import base 16 | 17 | 18 | class Snapshot(base.Base): 19 | requestHost = 'snapshot.api.qcloud.com' 20 | -------------------------------------------------------------------------------- /QcloudApi/modules/sts.py: -------------------------------------------------------------------------------- 1 | # Copyright 1999-2018 Tencent Ltd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from QcloudApi.modules import base 16 | 17 | 18 | class Sts(base.Base): 19 | """Security Token Service. 20 | 21 | document: https://cloud.tencent.com/document/product/598 22 | """ 23 | requestHost = 'sts.api.qcloud.com' 24 | -------------------------------------------------------------------------------- /QcloudApi/modules/tbaas.py: -------------------------------------------------------------------------------- 1 | # Copyright 1999-2018 Tencent Ltd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from QcloudApi.modules import base 16 | 17 | 18 | class Tbaas(base.Base): 19 | """Tencent Blockchain as a Service. 20 | 21 | document: https://cloud.tencent.com/document/product/663 22 | """ 23 | requestHost = 'tbaas.api.qcloud.com' 24 | -------------------------------------------------------------------------------- /QcloudApi/modules/tdsql.py: -------------------------------------------------------------------------------- 1 | # Copyright 1999-2017 Tencent Ltd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from QcloudApi.modules import base 16 | 17 | 18 | class Tdsql(base.Base): 19 | requestHost = 'tdsql.api.qcloud.com' 20 | -------------------------------------------------------------------------------- /QcloudApi/modules/tmt.py: -------------------------------------------------------------------------------- 1 | # Copyright 1999-2017 Tencent Ltd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from QcloudApi.modules import base 16 | 17 | 18 | class Tmt(base.Base): 19 | """Tencent Machine Translation. 20 | 21 | document: https://cloud.tencent.com/document/product/551 22 | """ 23 | requestHost = 'tmt.api.qcloud.com' 24 | -------------------------------------------------------------------------------- /QcloudApi/modules/trade.py: -------------------------------------------------------------------------------- 1 | # Copyright 1999-2017 Tencent Ltd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from QcloudApi.modules import base 16 | 17 | 18 | class Trade(base.Base): 19 | requestHost = 'trade.api.qcloud.com' 20 | -------------------------------------------------------------------------------- /QcloudApi/modules/vod.py: -------------------------------------------------------------------------------- 1 | # Copyright 1999-2017 Tencent Ltd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from QcloudApi.modules import base 16 | 17 | 18 | class Vod(base.Base): 19 | requestHost = 'vod.api.qcloud.com' 20 | -------------------------------------------------------------------------------- /QcloudApi/modules/vpc.py: -------------------------------------------------------------------------------- 1 | # Copyright 1999-2017 Tencent Ltd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from QcloudApi.modules import base 16 | 17 | 18 | class Vpc(base.Base): 19 | requestHost = 'vpc.api.qcloud.com' 20 | -------------------------------------------------------------------------------- /QcloudApi/modules/wenzhi.py: -------------------------------------------------------------------------------- 1 | # Copyright 1999-2017 Tencent Ltd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from QcloudApi.modules import base 16 | 17 | 18 | class Wenzhi(base.Base): 19 | requestHost = 'wenzhi.api.qcloud.com' 20 | -------------------------------------------------------------------------------- /QcloudApi/modules/yunsou.py: -------------------------------------------------------------------------------- 1 | # Copyright 1999-2017 Tencent Ltd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from QcloudApi.modules import base 16 | 17 | 18 | class Yunsou(base.Base): 19 | requestHost = 'yunsou.api.qcloud.com' 20 | -------------------------------------------------------------------------------- /QcloudApi/qcloudapi.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | from QcloudApi.modules import base 5 | 6 | 7 | class QcloudApi(object): 8 | def __init__(self, module, config): 9 | self.module = module 10 | self.config = config 11 | 12 | def _factory(self, module, config): 13 | if (module == 'cdb'): 14 | from .modules.cdb import Cdb 15 | service = Cdb(config) 16 | elif (module == 'account'): 17 | from .modules.account import Account 18 | service = Account(config) 19 | elif (module == 'cvm'): 20 | from .modules.cvm import Cvm 21 | service = Cvm(config) 22 | elif (module == 'image'): 23 | from .modules.image import Image 24 | service = Image(config) 25 | elif (module == 'lb'): 26 | from .modules.lb import Lb 27 | service = Lb(config) 28 | elif (module == 'sec'): 29 | from .modules.sec import Sec 30 | service = Sec(config) 31 | elif (module == 'trade'): 32 | from .modules.trade import Trade 33 | service = Trade(config) 34 | elif (module == 'bill'): 35 | from .modules.bill import Bill 36 | service = Bill(config) 37 | elif (module == 'monitor'): 38 | from .modules.monitor import Monitor 39 | service = Monitor(config) 40 | elif (module == 'cdn'): 41 | from .modules.cdn import Cdn 42 | service = Cdn(config) 43 | elif (module == 'vpc'): 44 | from .modules.vpc import Vpc 45 | service = Vpc(config) 46 | elif (module == 'vod'): 47 | from .modules.vod import Vod 48 | service = Vod(config) 49 | elif (module == 'yunsou'): 50 | from .modules.yunsou import Yunsou 51 | service = Yunsou(config) 52 | elif (module == 'wenzhi'): 53 | from .modules.wenzhi import Wenzhi 54 | service = Wenzhi(config) 55 | elif (module == 'market'): 56 | from .modules.market import Market 57 | service = Market(config) 58 | elif (module == 'live'): 59 | from .modules.live import Live 60 | service = Live(config) 61 | elif (module == 'eip'): 62 | from .modules.eip import Eip 63 | service = Eip(config) 64 | elif (module == 'cbs'): 65 | from .modules.cbs import Cbs 66 | service = Cbs(config) 67 | elif (module == 'snapshot'): 68 | from .modules.snapshot import Snapshot 69 | service = Snapshot(config) 70 | elif (module == 'scaling'): 71 | from .modules.scaling import Scaling 72 | service = Scaling(config) 73 | elif (module == 'cmem'): 74 | from .modules.cmem import Cmem 75 | service = Cmem(config) 76 | elif (module == 'tdsql'): 77 | from .modules.tdsql import Tdsql 78 | service = Tdsql(config) 79 | elif (module == 'bm'): 80 | from .modules.bm import Bm 81 | service = Bm(config) 82 | elif (module == 'bmlb'): 83 | from .modules.bmlb import Bmlb 84 | service = Bmlb(config) 85 | elif (module == 'redis'): 86 | from .modules.redis import Redis 87 | service = Redis(config) 88 | elif (module == 'dfw'): 89 | from .modules.dfw import Dfw 90 | service = Dfw(config) 91 | elif (module == 'ccs'): 92 | from .modules.ccs import Ccs 93 | service = Ccs(config) 94 | elif (module == 'feecenter'): 95 | from .modules.feecenter import Feecenter 96 | service = Feecenter(config) 97 | elif (module == 'cns'): 98 | from .modules.cns import Cns 99 | service = Cns(config) 100 | elif (module == 'bmeip'): 101 | from .modules.bmeip import Bmeip 102 | service = Bmeip(config) 103 | elif (module == 'bmvpc'): 104 | from .modules.bmvpc import Bmvpc 105 | service = Bmvpc(config) 106 | elif module == 'bgpip': 107 | from .modules.bgpip import Bgpip 108 | service = Bgpip(config) 109 | elif module == 'scf': 110 | from .modules.scf import Scf 111 | service = Scf(config) 112 | elif module == 'apigateway': 113 | from .modules.apigateway import APIGateway 114 | service = APIGateway(config) 115 | elif module == 'batch': 116 | from .modules.batch import Batch 117 | service = Batch(config) 118 | elif module == 'cloudaudit': 119 | from .modules.cloudaudit import CloudAudit 120 | service = CloudAudit(config) 121 | elif module == 'tmt': 122 | from .modules.tmt import Tmt 123 | service = Tmt(config) 124 | elif module == 'partners': 125 | from .modules.partners import Partners 126 | service = Partners(config) 127 | elif module == 'tbaas': 128 | from .modules.tbaas import Tbaas 129 | service = Tbaas(config) 130 | elif module == 'athena': 131 | from .modules.athena import Athena 132 | service = Athena(config) 133 | elif module == 'emr': 134 | from .modules.emr import Emr 135 | service = Emr(config) 136 | elif module == 'sts': 137 | from .modules.sts import Sts 138 | service = Sts(config) 139 | elif module == 'ccr': 140 | from .modules.ccr import Ccr 141 | service = Ccr(config) 142 | elif module == 'dc': 143 | from .modules.dc import Dc 144 | service = Dc(config) 145 | else: 146 | config.setdefault("endpoint", module + '.api.qcloud.com') 147 | service = base.Base(config) 148 | 149 | return service 150 | 151 | def setSecretId(self, secretId): 152 | self.config['secretId'] = secretId 153 | 154 | def setSecretKey(self, secretKey): 155 | self.config['secretKey'] = secretKey 156 | 157 | def setRequestMethod(self, method): 158 | self.config['method'] = method 159 | 160 | def setRegion(self, region): 161 | self.config['Region'] = region 162 | 163 | def setSignatureMethod(self, SignatureMethod): 164 | self.config['SignatureMethod'] = SignatureMethod 165 | 166 | def generateUrl(self, action, params): 167 | service = self._factory(self.module, self.config) 168 | return service.generateUrl(action, params) 169 | 170 | def call(self, action, params, req_timeout=None, debug=False): 171 | """ 172 | @type action: string 173 | @param action: action interface 174 | 175 | @type params: dict 176 | @param params: interface parameters 177 | 178 | @type req_timeout: int 179 | @param req_timeout: request timeout(seconds) 180 | 181 | @type debug: bool 182 | @param debug: debug switch 183 | """ 184 | service = self._factory(self.module, self.config) 185 | if req_timeout is not None: 186 | service.set_req_timeout(req_timeout) 187 | if debug: 188 | service.open_debug() 189 | 190 | methods = dir(service) 191 | for method in methods: 192 | if (method == action): 193 | func = getattr(service, action) 194 | return func(params) 195 | 196 | return service.call(action, params) 197 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![pypi version](https://img.shields.io/pypi/v/qcloudapi-sdk-python.svg)](https://pypi.python.org/pypi/qcloudapi-sdk-python) 2 | [![Build Status](https://travis-ci.org/QcloudApi/qcloudapi-sdk-python.svg?branch=master)](https://travis-ci.org/QcloudApi/qcloudapi-sdk-python) 3 | [![Coverage Status](https://coveralls.io/repos/github/QcloudApi/qcloudapi-sdk-python/badge.svg?branch=master)](https://coveralls.io/github/QcloudApi/qcloudapi-sdk-python) 4 | 5 | # qcloudapi-sdk-python 6 | 7 | qcloudapi-sdk-python是为了让Python开发者能够在自己的代码里更快捷方便的使用腾讯云的API而开发的SDK工具包。 8 | 9 | ## 资源 10 | 11 | * [公共参数](https://www.qcloud.com/document/api/213/6976) 12 | * [API列表](https://www.qcloud.com/document/api) 13 | * [错误码](https://www.qcloud.com/document/api/213/10146) 14 | 15 | ## 入门 16 | 17 | 1. 申请[安全凭证](https://console.qcloud.com/capi)。 18 | 在第一次使用云API之前,用户首先需要在腾讯云网站上申请安全凭证,安全凭证包括 SecretId 和 SecretKey, SecretId 是用于标识 API 调用者的身份,SecretKey是用于加密签名字符串和服务器端验证签名字符串的密钥。SecretKey 必须严格保管,避免泄露。 19 | 20 | ## 安装 21 | 22 | $ pip install qcloudapi-sdk-python 23 | 24 | 或者下载源码安装 25 | 26 | $ git clone https://github.com/QcloudApi/qcloudapi-sdk-python 27 | $ cd qcloudapi-sdk-python 28 | $ python setup.py install 29 | 30 | ## 示例 31 | 32 | ```python 33 | # -*- coding: utf8 -*- 34 | from QcloudApi.qcloudapi import QcloudApi 35 | 36 | # 设置需要加载的模块 37 | module = 'cvm' 38 | 39 | # 对应接口的接口名,请参考wiki文档上对应接口的接口名 40 | action = 'DescribeInstances' 41 | 42 | # 云API的公共参数 43 | config = { 44 | 'Region': 'ap-guangzhou', 45 | 'secretId': '您的secretId', 46 | 'secretKey': '您的secretKey', 47 | 'method': 'GET', 48 | 'SignatureMethod': 'HmacSHA1', 49 | # 只有cvm需要填写version,其他产品不需要 50 | 'Version': '2017-03-12' 51 | } 52 | 53 | # 接口参数,根据实际情况填写,支持json 54 | # 例如数组可以 "ArrayExample": ["1","2","3"] 55 | # 例如字典可以 "DictExample": {"key1": "value1", "key2": "values2"} 56 | action_params = { 57 | 'Limit':1, 58 | } 59 | 60 | try: 61 | service = QcloudApi(module, config) 62 | 63 | # 请求前可以通过下面几个方法重新设置请求的secretId/secretKey/Region/method/SignatureMethod参数 64 | # 重新设置请求的Region 65 | #service.setRegion('ap-shanghai') 66 | 67 | # 打印生成的请求URL,不发起请求 68 | print(service.generateUrl(action, action_params)) 69 | # 调用接口,发起请求,并打印返回结果 70 | print(service.call(action, action_params)) 71 | except Exception as e: 72 | import traceback 73 | print('traceback.format_exc():\n%s' % traceback.format_exc()) 74 | ``` 75 | 76 | ## 模块对照表 77 | 78 | 每个产品都有自己的独立域名,例如云服务器对应的域名为 cvm.api.qcloud.com ,一般域名的第一段对应产品名的缩写(特殊情况会另行说明),此例中为 cvm 。在 SDK 中,产品名缩写对应为模块名,放置于 QcloudApi/modules 目录下(base.py 例外,它是基类),对于没有在 modules 目录列出的产品,依然可以使用。例如在 tests/integration/ckafka 目录下的测试文件 test\_list\_instance.py ,表明了调用未显式注册的产品也可以被正常使用,前提是使用产品名和域名首段一致,如果不一致,则以域名首段为准,在使用cmq的产品时将会发生这种情况。 79 | 80 | 以下列出目前已经显式支持或者可以动态支持的产品列表,顺序依照官网 API 文档的权重。有些产品已经支持或者部分支持 API 3.0 ,在表格中有注明,建议用户使用 API 3.0 对应的 [SDK](https://github.com/TencentCloud/tencentcloud-sdk-python)。 81 | 82 | 请注意,并非所有腾讯云上的产品都支持腾讯云 API ,有部分产品例如对象存储服务( COS )有自己独立的 API 和 SDK ,详情请咨询对应产品的技术支持人员。 83 | 84 | 部分产品根据自身业务特点,拆分成多个服务,其调用域名根据功能而不同,此种情况下模块名会有多个,请配合官网文档进行使用,本文档不另作说明了。 85 | 86 | 以下信息更新于2018-09-25 87 | 88 | | 产品中文名 | 模块名 | 显式支持 | 支持 API 3.0 | 备注 89 | |-|-|-|-|-| 90 | | 云服务器 | cvm、image、dfw、eip | 是 | 是 | | 91 | | 云硬盘 | cbs、snapshot | 是 | 是 | | 92 | | 黑石物理服务器 | bm、bmlb、bmeip、bmvpc | 是 | 部分 | | 93 | | 容器服务 | ccs、ccr | 是 | 否 | | 94 | | 弹性伸缩 | scaling | 是 | 是 | | 95 | | 负载均衡 | lb | 是 | 否 | | 96 | | 无服务器云函数 | scf | 是 | 部分 | | 97 | | 私有网络 | vpc | 是 | 是 | | 98 | | 批量计算 | batch | 是 | 是 | | 99 | | API网关 | apigateway | 是 | 否 | | 100 | | 专线接入 | dc | 是 | 是 | | 101 | | 动态加速网络 | dsa | 否 | 否 | | 102 | | 消息队列 CKafka | ckafka | 否 | 否 | | 103 | | 消息队列 IoT MQ | mqiot | 否 | 否 | | 104 | | 消息队列 CMQ | cmq-queue-{REGION} | 否 | 否 | 产品域名不固定,和区域有关 | 105 | | 数据库 MySQL | cdb | 是 | 是 | | 106 | | 数据库 MariaDB(TDSQL)| tdsql | 是 | 是 | | 107 | | 数据库 SQL Server | sqlserver | 否 | 是 | | 108 | | 内容分发网络 | cdn | 是 | 否 | | 109 | | 弹性缓存 Redis | redis | 是 | 部分 | | 110 | | 弹性缓存 Memcached | cmem | 是 | 否 | | 111 | | 文档数据库 MongoDB | mongodb | 否 | 否 | | 112 | | 云监控 | monitor | 是 | 否 | | 113 | | TBaaS | tbaas | 是 | 是 | | 114 | | 访问管理 | cam、sts | 部分 | 否 | | 115 | | 大禹网络安全 | bgpip、shield | 部分 | 否 | | 116 | | 天御业务安全防护 | sec | 是 | 否 | 产品域名为 csec 117 | | 云审计 | cloudaudit | 是 | 否 | | 118 | | 云解析 | cns | 是 | 否 | | 119 | | SSL 证书 | wss | 否 | 否 | | 120 | | 云搜 | yunsou | 是 | 否 | | 121 | | 文智自然语言处理 | wenzhi | 是 | 否 | | 122 | | 点播 | vod | 是 | 否 | | 123 | | 云市场 | market | 是 | 是 | | 124 | | 直播 | live | 是 | 部分 | | 125 | | 腾讯机器翻译 | tmt | 是 | 是 | | 126 | | 物联网通信 | iotcloud | 否 | 否 | | 127 | | 弹性 Mapreduce | emr | 是 | 否 | | 128 | | 账号相关 | trade、tag、account、feecenter | 部分 | 否 | | 129 | | 渠道合作伙伴 | partners | 是 | 是 | | 130 | | 金融智能客服 | athena | 是 | 否 | | 131 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | =============================== 2 | The Qcloud API SDK for Python 3 | =============================== 4 | 5 | Qcloud Python SDK is the official software development kit, which allows Python developers to write software that makes use of qcloud services like CVM and CBS. 6 | 7 | The SDK works on Python versions: 8 | 9 | * 2.7 and greater, including 3.x.x 10 | 11 | Quick Start 12 | ----------- 13 | First, install the library: 14 | 15 | .. code-block:: sh 16 | 17 | $ pip install qcloudapi-sdk-python 18 | 19 | or download source code from github and install: 20 | 21 | .. code-block:: sh 22 | 23 | $ git clone https://github.com/QcloudApi/qcloudapi-sdk-python.git 24 | $ cd qcloudapi-sdk-python 25 | $ python setup.py install 26 | 27 | Then, from a Python interpreter or script: 28 | 29 | .. code-block:: python 30 | 31 | >>> from QcloudApi.qcloudapi import QcloudApi 32 | >>> module = 'cvm' 33 | >>> action = 'DescribeInstances' 34 | >>> config = {'Region':'ap-guangzhou', 'secretId':'xxxx', 'secretKey':'xxxx', 'Version':'2017-03-20'} 35 | >>> params = {'Limit':1} 36 | >>> service = QcloudApi(module, config) 37 | >>> service.call(action, params) 38 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [bdist_wheel] 2 | universal=1 3 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | distutils/setuptools install script. 5 | """ 6 | import os 7 | from setuptools import setup, find_packages 8 | 9 | import QcloudApi 10 | 11 | ROOT = os.path.dirname(__file__) 12 | 13 | setup( 14 | name='qcloudapi-sdk-python', 15 | version=QcloudApi.__version__, 16 | description='The Qcloud Api SDK for Python', 17 | long_description=open('README.rst').read(), 18 | author='Qcloud', 19 | url='https://github.com/QcloudApi/qcloudapi-sdk-python.git', 20 | maintainer_email="QcloudApi@tencent.com", 21 | scripts=[], 22 | packages=find_packages(exclude=["tests*"]), 23 | license="Apache License 2.0", 24 | platforms='any', 25 | classifiers=[ 26 | 'Development Status :: 5 - Production/Stable', 27 | 'Intended Audience :: Developers', 28 | 'License :: OSI Approved :: Apache Software License', 29 | 'Programming Language :: Python', 30 | 'Programming Language :: Python :: 2.6', 31 | 'Programming Language :: Python :: 2.7', 32 | 'Programming Language :: Python :: 3', 33 | 'Programming Language :: Python :: 3.1', 34 | 'Programming Language :: Python :: 3.2', 35 | 'Programming Language :: Python :: 3.3', 36 | 'Programming Language :: Python :: 3.4', 37 | 'Programming Language :: Python :: 3.5', 38 | 'Programming Language :: Python :: 3.6', 39 | ], 40 | ) 41 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QcloudApi/qcloudapi-sdk-python/9b097e4f4089cb6432ada7593999fab92f31fb43/tests/__init__.py -------------------------------------------------------------------------------- /tests/demo.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | # 引入云API入口模块 5 | from QcloudApi.qcloudapi import QcloudApi 6 | 7 | ''' 8 | module: 设置需要加载的模块 9 | 已有的模块列表: 10 | cvm 对应 cvm.api.qcloud.com 11 | cdb 对应 cdb.api.qcloud.com 12 | lb 对应 lb.api.qcloud.com 13 | trade 对应 trade.api.qcloud.com 14 | sec 对应 csec.api.qcloud.com 15 | image 对应 image.api.qcloud.com 16 | monitor 对应 monitor.api.qcloud.com 17 | cdn 对应 cdn.api.qcloud.com 18 | ''' 19 | module = 'cvm' 20 | 21 | ''' 22 | action: 对应接口的接口名,请参考wiki文档上对应接口的接口名 23 | ''' 24 | action = 'DescribeInstances' 25 | 26 | ''' 27 | config: 云API的公共参数 28 | ''' 29 | config = { 30 | 'Region': 'ap-guangzhou', 31 | 'secretId': '您的secretId', 32 | 'secretKey': '您的secretKey', 33 | } 34 | 35 | # 接口参数 36 | action_params = { 37 | 'Version': '2017-03-12', 38 | 'Filters': [{ 39 | 'Name': 'zone', 40 | 'Values': ['ap-guangzhou-1', 'ap-guangzhou-2'] 41 | }], 42 | 'limit': 1, 43 | } 44 | 45 | try: 46 | service = QcloudApi(module, config) 47 | print(service.generateUrl(action, action_params)) 48 | print(service.call(action, action_params)) 49 | except Exception as e: 50 | import traceback 51 | print('traceback.format_exc():\n%s' % traceback.format_exc()) 52 | -------------------------------------------------------------------------------- /tests/functional/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QcloudApi/qcloudapi-sdk-python/9b097e4f4089cb6432ada7593999fab92f31fb43/tests/functional/__init__.py -------------------------------------------------------------------------------- /tests/functional/test_cvm.py: -------------------------------------------------------------------------------- 1 | # Copyright 1999-2017 Tencent Ltd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | """Test cvm basic functionalities.""" 16 | 17 | 18 | from QcloudApi.common import request 19 | from QcloudApi import qcloudapi 20 | 21 | 22 | def test_describe_instances(monkeypatch): 23 | def mock(*args, **kwargs): 24 | return request.ResponseInternal(status=200) 25 | monkeypatch.setattr(request.ApiRequest, 'send_request', mock) 26 | config = { 27 | 'Region': 'gz', 28 | 'secretId': '123', 29 | 'secretKey': '456', 30 | } 31 | service = qcloudapi.QcloudApi('cvm', config) 32 | service.call('DescribInstances', {}) 33 | -------------------------------------------------------------------------------- /tests/integration/ckafka/test_list_instance.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 1999-2018 Tencent Ltd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | import json 16 | import os 17 | 18 | from QcloudApi import qcloudapi 19 | 20 | 21 | def test_describe_instances(): 22 | config = { 23 | "Region": "ap-guangzhou", 24 | "secretId": os.environ.get("TENCENTCLOUD_SECRET_ID"), 25 | "secretKey": os.environ.get("TENCENTCLOUD_SECRET_KEY"), 26 | } 27 | service = qcloudapi.QcloudApi("ckafka", config) 28 | result = service.call("ListInstance", {}, 29 | req_timeout=10, debug=True).decode("utf-8") 30 | assert json.loads(result)["code"] == 0 31 | -------------------------------------------------------------------------------- /tests/integration/cvm/test_describe_instances.py: -------------------------------------------------------------------------------- 1 | # Copyright 1999-2017 Tencent Ltd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | import json 16 | import os 17 | 18 | from QcloudApi import qcloudapi 19 | 20 | 21 | def test_describe_instances(): 22 | config = { 23 | "Region": "ap-guangzhou", 24 | "secretId": os.environ.get("TENCENTCLOUD_SECRET_ID"), 25 | "secretKey": os.environ.get("TENCENTCLOUD_SECRET_KEY"), 26 | } 27 | service = qcloudapi.QcloudApi("cvm", config) 28 | params = { 29 | "Version": "2017-03-12", 30 | "Limit": 1, 31 | } 32 | result = service.call("DescribeInstances", params, 33 | req_timeout=10, debug=True).decode("utf-8") 34 | assert len(json.loads(result)["Response"].get("InstanceSet", [])) == 1 35 | -------------------------------------------------------------------------------- /tests/unit/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QcloudApi/qcloudapi-sdk-python/9b097e4f4089cb6432ada7593999fab92f31fb43/tests/unit/__init__.py -------------------------------------------------------------------------------- /tests/unit/common/test_sign.py: -------------------------------------------------------------------------------- 1 | # Copyright 1999-2017 Tencent Ltd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from QcloudApi.common import sign 16 | 17 | 18 | def test_sign(): 19 | s = sign.Sign('secretIdFoo', 'secretKeyBar') 20 | params = { 21 | 'SecretId': 'secretIdFoo', 22 | 'Region': 'ap-guangzhou', 23 | 'SignatureMethod': 'HmacSHA1', 24 | 'Nonce': '1290303896666895346', 25 | 'Timestamp': '1512393162', 26 | 'Action': 'DescribeInstances', 27 | 'Version': '2017-03-12', 28 | } 29 | ss = s.make('cvm.api.qcloud.com', '/v2/index.php', params, 30 | method='POST') 31 | assert ss == 'p3n+pxBqF5JGZtDSxoVn5tGngf0=' 32 | 33 | 34 | def test_sign_post_lowercase(): 35 | s = sign.Sign('secretIdFoo', 'secretKeyBar') 36 | params = { 37 | 'SecretId': 'secretIdFoo', 38 | 'Region': 'ap-guangzhou', 39 | 'SignatureMethod': 'HmacSHA1', 40 | 'Nonce': '1290303896666895346', 41 | 'Timestamp': '1512393162', 42 | 'Action': 'DescribeInstances', 43 | 'Version': '2017-03-12', 44 | } 45 | ss = s.make('cvm.api.qcloud.com', '/v2/index.php', params, 46 | method='post') 47 | assert ss == 'p3n+pxBqF5JGZtDSxoVn5tGngf0=' 48 | 49 | 50 | def test_sign_hmacsha256(): 51 | s = sign.Sign('secretIdFoo', 'secretKeyBar') 52 | params = { 53 | 'SecretId': 'secretIdFoo', 54 | 'Region': 'ap-guangzhou', 55 | 'SignatureMethod': 'HmacSHA256', 56 | 'Nonce': '1290303896666895346', 57 | 'Timestamp': '1512393162', 58 | 'Action': 'DescribeInstances', 59 | 'Version': '2017-03-12', 60 | } 61 | ss = s.make('cvm.api.qcloud.com', '/v2/index.php', params, 62 | method='POST', sign_method='HmacSHA256') 63 | assert ss == 'B2T37FRSP6Fk0/q/cdfrTE0p3zX5ooB/2BPWZUFpsj4=' 64 | 65 | 66 | def test_sign_get(): 67 | s = sign.Sign('secretIdFoo', 'secretKeyBar') 68 | params = { 69 | 'SecretId': 'secretIdFoo', 70 | 'Region': 'ap-guangzhou', 71 | 'SignatureMethod': 'HmacSHA1', 72 | 'Nonce': '1290303896666895346', 73 | 'Timestamp': '1512393162', 74 | 'Action': 'DescribeInstances', 75 | 'Version': '2017-03-12', 76 | } 77 | ss = s.make('cvm.api.qcloud.com', '/v2/index.php', params, 78 | method='GET') 79 | assert ss == '5HAq1BOKNLEE2/uauWnp6Zv9Z3c=' 80 | -------------------------------------------------------------------------------- /tests/unit/modules/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QcloudApi/qcloudapi-sdk-python/9b097e4f4089cb6432ada7593999fab92f31fb43/tests/unit/modules/__init__.py -------------------------------------------------------------------------------- /tests/unit/modules/test_basic.py: -------------------------------------------------------------------------------- 1 | # Copyright 1999-2017 Tencent Ltd. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | """Basic test for modules, simply check if import succeed.""" 16 | 17 | 18 | from QcloudApi.modules import apigateway 19 | from QcloudApi.modules import account 20 | from QcloudApi.modules import athena 21 | from QcloudApi.modules import batch 22 | from QcloudApi.modules import bgpip 23 | from QcloudApi.modules import bill 24 | from QcloudApi.modules import bm 25 | from QcloudApi.modules import bmeip 26 | from QcloudApi.modules import bmlb 27 | from QcloudApi.modules import bmvpc 28 | from QcloudApi.modules import cbs 29 | from QcloudApi.modules import ccr 30 | from QcloudApi.modules import ccs 31 | from QcloudApi.modules import cdb 32 | from QcloudApi.modules import cdn 33 | from QcloudApi.modules import cloudaudit 34 | from QcloudApi.modules import cmem 35 | from QcloudApi.modules import cns 36 | from QcloudApi.modules import cvm 37 | from QcloudApi.modules import dc 38 | from QcloudApi.modules import dfw 39 | from QcloudApi.modules import eip 40 | from QcloudApi.modules import emr 41 | from QcloudApi.modules import feecenter 42 | from QcloudApi.modules import image 43 | from QcloudApi.modules import lb 44 | from QcloudApi.modules import live 45 | from QcloudApi.modules import market 46 | from QcloudApi.modules import monitor 47 | from QcloudApi.modules import partners 48 | from QcloudApi.modules import redis 49 | from QcloudApi.modules import scaling 50 | from QcloudApi.modules import scf 51 | from QcloudApi.modules import sec 52 | from QcloudApi.modules import snapshot 53 | from QcloudApi.modules import sts 54 | from QcloudApi.modules import tbaas 55 | from QcloudApi.modules import tdsql 56 | from QcloudApi.modules import tmt 57 | from QcloudApi.modules import trade 58 | from QcloudApi.modules import vod 59 | from QcloudApi.modules import vpc 60 | from QcloudApi.modules import wenzhi 61 | from QcloudApi.modules import yunsou 62 | 63 | 64 | def test_import(): 65 | """test to ensure pr #22 will never happen again.""" 66 | pass 67 | -------------------------------------------------------------------------------- /tox.ini: -------------------------------------------------------------------------------- 1 | [tox] 2 | minversion = 1.8 3 | skipsdist = True 4 | envlist = py{27,35,36},pep8 5 | 6 | [testenv] 7 | deps = 8 | pytest 9 | pytest-cov 10 | usedevelop = True 11 | commands = 12 | py.test {toxinidir}/tests 13 | passenv = 14 | TENCENTCLOUD_SECRET_ID 15 | TENCENTCLOUD_SECRET_KEY 16 | HTTPS_PROXY 17 | 18 | [testenv:coveralls] 19 | passenv = TRAVIS TRAVIS_JOB_ID TRAVIS_BRANCH COVERALLS_REPO_TOKEN 20 | deps = 21 | {[testenv]deps} 22 | coveralls 23 | commands = 24 | py.test --cov {toxinidir}/QcloudApi {toxinidir}/tests 25 | coveralls 26 | 27 | [testenv:pep8] 28 | deps = pycodestyle 29 | commands = 30 | pycodestyle 31 | 32 | [pycodestyle] 33 | ignore = 34 | exclude=.tox/,doc/ 35 | show-source = True 36 | --------------------------------------------------------------------------------