Skip to content
Yuzhang Hu edited this page Oct 24, 2016 · 7 revisions

API for Python

Skull do not support Python service, so only module related APIs provided.

Indexes:

  • Txn
  • TxnData
  • Logger
  • Http Request/Response

Txn

API Module: skullpy.txn

Besides module_init and module_release, all other module_ callbacks will pass the Txn Object there as a parameter. Txn means the Transaction object, which is used for:

  • Get/set transaction shared data
  • Identify the transaction status
  • Communicate with Service

Txn.data()

Return the transaction shared data, this data has been converted to the correct type already.

Txn.status()

This API return the status in currently, values are:

  • TXN_OK: No errors, everything is good.
  • TXN_ERROR: Error occurred, so users should prepare to construct error response then.
  • TXN_TIMEOUT: Timeout occurred if users configure a timeout item in workflow.

Txn.iocall(service_name, api_name, request_msg, bio_idx=None, api_cb=None)

TxnData

API Module: skullpy.txndata

TxnData is a parameter in module_pack stage, users use it to send the response back to the client.

TxnData.append(data)

Append a bytes/string data to the response, which will be send back to client then.

Logger

API Module: skullpy.logger

logger.trace(msg)
logger.debug(msg)
logger.info(code, msg)
logger.warn(code, msg, suggestion)
logger.error(code, msg, solution)
logger.fatal(code, msg, solution)

The usage is the same as Cpp language.

Http Request/Response

API Module: skullpy.http

Since Python is powerful by handle the HTTP stuffs, to better integrate with other web service like Nginx, Skull provide a http wrapper by using WebOb internally.

Example code can be found here

http.Request(data)

Construct a http request object with the raw input HTTP content data.

http.Request.parse()

After construct the request object, then call this API to parse it to a WebOb Request object, then users can use it to get the http data very easily.

http.Request.getEnv()

In case some users want to get the environ variable which be used for constructing the request object, this API would return that for the purpose.

http.Response.getFullContent()

After users handling all the logic, and want to construct a http response sending back to client, create the http.Response object, and add the http content, then call this API to get a full string of the http response content. Next, call txndata.append(data) to send it back.

Clone this wiki locally