Reserved Variables
Overview
Data Lab Functions provides two reserved variables that offer valuable information and functionality to developers when creating Add-ons: REQUEST
and LOG
.
The REQUEST Variable
On each request made to the Data Lab Functions API, a REQUEST
variable of type Dict
is automatically injected into the kernel and can be accessed like any other variable. This REQUEST
dictionary contains essential information about the HTTP request, allowing developers to access various request details. The REQUEST
dictionary includes the following key-value pairs:
'info'
: A dictionary containing additional request-related information.'id'
: A unique ID assigned to the request.'user_id'
: The UUID of the Seeq user invoking the request.'notebook'
: The path and name of the API notebook handling the request.'method'
: The HTTP method used for the request (e.g., GET, POST, etc.).'endpoint'
: The name of the API endpoint being accessed.
'body'
: If applicable, the request body in either string or dictionary format, parsed from JSON or Form-Encoded name-value pairs.'args'
: A dictionary containing the parsed query string name-value pairs.'headers'
: A dictionary with HTTP header name-value pairs.
{
"info": {
"id": 3,
"user_id": "C3A1CB77-071A-4E2A-87A4-B3E3D465E13E",
"notebook": "api",
"method": "GET",
"endpoint": "test"
},
"body": "",
"args": {},
"headers": {}
}
Developers can access this REQUEST
variable within their Add-ons to understand crucial context information about incoming requests and take appropriate actions based on the request details.
Example:
The following code will print the value of the REQUEST
and REQUEST['body']
key for the POST
endpoint the REQUEST
for the GET
:
The LOG Object
Data Lab Functions also provides a Python file logger named LOG
, which Add-ons can utilize to write log messages. The LOG
object allows developers to invoke standard logging methods, including debug
, info
, warning
, and error
, enabling effective debugging and monitoring of Add-ons.
LOG.info("Here is some information")
Alternatively, developers can use Python's logging module and the getLogger()
method to retrieve the logger associated with the Data Lab Functions Add-on. This can be achieved by passing the name of the Data Lab Functions Add-on logger, stored in the SEEQ_DATALAB_FUNCTIONS_LOGGER
environment variable.
Here's an example of how to access the logger using Python's logging module:
import os
import logging
my_log = logging.getLogger(os.environ['SEEQ_DATALAB_FUNCTIONS_LOGGER'])
my_log.info("Hello World!")