Skip to main content

About ProcessorContext

Class nifiapi.properties.ProcessorContext

The ProcessContext class provides an interface for retrieving the values of properties defined by the PropertyDescriptor class.

Attributes:

NameTypeDescription
nameStringName of the Processor
getProperty(PropertyDescriptor)CallableExpects an instance of a PropertyDescriptor class or a string representing the name of a registered property;

Returns an instance of PythonPropertyValue
getProperties()CallableReturns a dictionary of available properties as key-value pairs;

Dictionary keys are instances of the PropertyDescriptor class, and values are represented as strings

e.g.:

from nifiapi.properties import PropertyDescriptor

PROPERTY = PropertyDescriptor(
name="Property A",
description='''
An example property descriptor.
''',
)

descriptor = context.getProperty(PROPERTY)
note

getProperty method accepts either a string representing the name of the descriptor or an instance of a PropertyDescriptor class.

Accessing Property Values

A value of the property can be accessed through ProcessContext.

Example of a method returning all defined properties:

from nifiapi.flowfiletransform import FlowFileTransform
from nifiapi.properties import ProcessContext


class Processor(FlowFileTransform):
(...)

def get_properties(self, context: ProcessContext) -> dict:
'''
Load processor configuration from ProcessContex.

Parameters:
context (ProcessContext)

Returns:
Dictionary(String: Mixed(None|String))
'''
return {
descriptor.name: value
for descriptor, value in context.getProperties().items()
}

Accessing Dynamic Properties

Apache NiFi, allows user to dynamically define custom properties, beyond the predefined set of property descriptors. These properties can be used to configure the processor's behavior in a flexible manner, enabling more dynamic and adaptable data flows.

Example of retrieving dynamic properties:

from nifiapi.flowfiletransform import FlowFileTransform
from nifiapi.properties import ProcessContext, PropertyDescriptor


class Processor(FlowFileTransform):
(...)

def get_dynamic_properties(self, context: ProcessContext) -> dict:
'''
Get a dictonary of all existing dynamic properties.

Parameters:
context (ProcessContext)

Returns:
Dictionary(string: Mixed(None|String))
'''
return {
descriptor.name: value
for descriptor, value in context.getProperties().items()
if descriptor.dynamic
}