Block Code Example to use input/output dents & generate Logs & Metrics

This sample Block code takes some input from the user and then publishes logs and metrics when the Block executes. This Block runs in Batch mode.

from pipelineblocksdk.api.Singleton import Singleton
from pipelineblocksdk.construct.base.BatchBlock import BatchBlock

# Following code is the definition for a batch block
class MyBlock(BatchBlock, Singleton):

    # This is the entrypoint for the block. This is a mandatory function.
    def run(self):
        #These lines of code are used to read the values from two different input dents or multiple input dents 
        # input dictionary to accept values from user and use them in code 
        a = self.input_dict["data_1"]["a"]
        b = self.input_dict["data_1"]["b"]
        c = self.input_dict["data_2"]["c"]
        d = self.input_dict["data_2"]["d"]
        e = a + c
        f = b + d
        # Assuming a & c is integer values and b & d are strring values lets write a small code 
        print("The sum of a + c is = ", e)
        print("The sum of b + d is = ", f)

        # Set the output parameter
        output_dict = dict()
        # Output dict to store values of a & c, b & d in e & f respectively if it is to be used by other blocks 
        output_dict['e'] = e
        output_dict['f'] = f
        # Set the status of the block as completed
        self.block_status = "COMPLETED"

        return output_dict

This Block requires the following 2 inputs configured as part of the Block:

Input 1

data_1 = {
  "a": "<enter value for a>",
  "b": "<enter value for b>"

Input 2

data_2 = {
  "c": "<enter value for c>",
  "d": "<enter value for d>"