Notebook Context

Notebook Context allows you to change the Losant Notebook’s configuration at run time.

Notebook Context

Notebook Context can be useful for the following reasons:

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.

Execute Node 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:

Manual Execution 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 Config Context

Notebook Input

During Notebook execution, context will be available at INPUT_DIR/context.json.

Given the following context:

{
  "nested": {
    "data": {
      "users": [
        {
          "email": "hello@losant.com",
          "id": "5d65841f1883530006f8b513"
        },
        {
          "email": "test@losant.com",
          "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'] # peter@losant.com

More information about accessing generated input files can be found here.

Was this page helpful?


Still looking for help? You can also search the Losant Forums or submit your question there.