Skip to main content

About ExpressionLanguageScope

Class nifiapi.properties.ExpressionLanguageScope; Type Enum

When defining a PropertyDescriptor, a developer may choose to provide an expression_language_scope attribute. The scope defines if and how NiFi Expression Language is used for a property.

Attributes

ValueDescription
NONEExpression Language will not be evaluated for this property
ENVIRONMENTExpression Language may be used and may reference environment variables but may not reference FlowFile attributes. Useful when dealing with secrets
FLOWFILE_ATTRIBUTESFlowFile attributes may be referenced when configuring the property value

e.g.:

from nifiapi.properties import (
PropertyDescriptor,
StandardValidators,
ExpressionLanguageScope
)

PROPERTY = PropertyDescriptor(
name="Property A",
description='''
Property value can contain Expression Language; Scope of the language
is limited to function not referencing FlowFile attributes.
''',
validators=[
StandardValidators.NON_EMPTY_EL_VALIDATOR
],
expression_language_scope=ExpressionLanguageScope.ENVIRONMENT,
)

For information on EL refer to NiFi Documentation.

FLOWFILE_ATTRIBUTES

caution

If ExpressionLanguageScope value is set to FLOWFILE_ATTRIBUTES, PropertyDescriptor should be evaluated only inside transform method.

You can check the EL scope by checking PropertyDescriptor.expression_language_scope property.

Example of a method returning all properties that can be evaluated without accessing FlowFile attributes:

from nifiapi.flowfiletransform import FlowFileTransform
from nifiapi.properties import (
ProcessContext,
PropertyDescriptor,
ExpressionLanguageScope
)
from typing import List


class Processor(FlowFileTransform):
(...)

def get_properties(
self, context: ProcessContext
) -> List[PropertyDescriptor]:
'''
Return properites that can be evaluated without FlowFile's
attribute map.

Parameters:
context (ProcessContext)

Returns:
Dictionary(String: Mixed(String | None))
'''
attribute_scope = ExpressionLanguageScope.FLOWFILE_ATTRIBUTES
return {
descriptor.name: descriptor.evaluateAttributeExpressions().value
for descriptor in context.getProperties().keys()
if descriptor.expression_language_scope != attribute_scope
}