credential is the object to store credential information
the keys can be found on APIKey documentation
it can calculate signature for OpenAPI:
>>> cred = Credential('my_public_key', 'my_private_key')
>>> cred.verify_ac({"foo": "bar"})
'd4411ab30953fb0bbcb1e7313081f05e4e91a394'
public_key –
private_key –
Config is the config of ucloud sdk, use for setting up
region (str) – Region is the region of backend service, See also Region list Documentation
project_id (str) – ProjectId is the unique identify of project, used for organize resources, Most of resources should belong to a project. Sub-Account must have an project id. See also Project list Documentation
base_url (str) – BaseUrl is the url of backend api
user_agent – UserAgent is an attribute for sdk client, used for distinguish who is using sdk. See also User Agent It will be appended to the end of sdk user-agent. eg. “MyAPP/0.10.1” -> “Python/3.7.0 Python-SDK/0.1.0 MyAPP/0.10.1”
timeout (int) – Timeout is timeout for every request.
max_retries (int) – MaxRetries is the number of max retry times. Set MaxRetries more than 0 to enable auto-retry for network and service availability problem if auto-retry is enabled, it will enable default retry policy using exponential backoff.
log_level (int) – LogLevel is equal to builtin logging level, if logLevel not be set, use INFO level as default.
invoke will invoke the action with arguments data and options
action (str) – the api action, like CreateUHostInstance
args (dict) – arguments of api(action), see doc: UCloud API Documentation
transport is the implementation of http client, use for send a request and return a http response
max_retries (int) – max retries is the max number of transport request when occur http error
backoff_factor (float) – backoff factor will calculate the backoff delay during retrying, the backoff delay = {backoff factor} * (2 ^ ({number of total retries} - 1))
status_forcelist (tuple) – the status code list that could be retried
the middleware object, see :mod:
the transport middleware
middleware is the object to store request/response handlers
>>> middleware = Middleware()
Add a request handler to prepare the request
>>> @middleware.request
... def prepare(req):
... req['Region'] = 'cn-bj2'
... return req
Add a response handler to log the response detail
>>> @middleware.response
... def logged(resp):
... print(resp)
... return resp
>>> len(middleware.request_handlers), len(middleware.response_handlers)
(1, 1)
exception is the exception handler register to add exception handler.
handler – exception handler function, receive exception object and raise a new exception or ignore it
index (int) – the position of handler in the handler list, default is append it to end