Notebook Context
Notebook Context allows you to change the WEGnology Notebook’s configuration at run time.
Notebook Context can be useful for the following reasons:
- Use data from a Workflow as Notebook Input or Output.
- Use payload data from a Workflow to dynamically configure Notebook behavior.
The maximum size of the Notebook Context object is 32KB.
Providing Context
There are two ways that you may provide the optional context to your notebook’s execution:
Notebook: Execute Node
The Notebook: Execute Node allows a Workflow to pass in payload data as your notebook’s context.
The example above uses the MongoDB Node to query a MongoDB database for additional data to provide as context to be used in notebook processing.
Manual Execution
When manually executing a Notebook you will have the option to provide JSON to use as context:
Accessing Context
If context was provided to the notebook execution via one of the above methods, it will be available for use in two ways:
Configuration Template
Context are accessible by using templates in the configuration for Notebook Inputs and Notebook Outputs:
Notebook Input
During Notebook execution, context will be available at INPUT_DIR/context.json
.
Given the following context:
{
"nested":{
"data":{
"users":[{
"email":"admin@weg.net",
"id":"5d65841f1883530006f8b513"
},
{
"email":"test@weg.net",
"id":"5d65841f1883530006f8b514"
}]
}
}
}
Particular properties can be accessed like so:
import os
import json
# Load context as json
context = json.load(os.path.join(os.environ['INPUT_DIR'], "context.json"))
users = context['nested']['data']['users']
userOneEmail = users[0]['email'] # admin@weg.net
More information about accessing generated input files can be found here.
Was this page helpful?
Still looking for help? You can also search the WEGnology Forums or submit your question there.