Skip to main content

About FlowFileSource

Class nifiapi.flowfilesource.FlowFileSource

All NiFi flows start with a Source Processor that creates new Flow Files either internally or from an external source, the FlowFileSource class provides a way to implement a Source Processor in Python.

Processors implementing the FlowFileSource class are expected to implement the create(ProcessContext) method, which should return an instance of FlowFileSourceResult.

The FlowFileSource class supports both life-cycle methods: onScheduled and onStopped.

By default there is a single relationship available for this class: success. Additional relations can be define and declared using getRelationships method. See Relationship for details.

It is possible to register custom properties by defining a getPropertyDescriptors method. See PropertyDescriptor for details.

Limitations

The create method can only return one FlowFileSourceResult, which means that only one FlowFile can be created at a time.

Implementation

See a boilerplate implementation.

from nifiapi.flowfilesource import (
FlowFileSource,
FlowFileSourceResult
)
from nifiapi.properties import (
ProcessContext,
PropertyDescriptor
)
from nifiapi.relationship import Relationship
from typing import List


class CreateFlowFile(FlowFileSource):

class Java:
implements = ['org.apache.nifi.python.processor.FlowFileSource']

class ProcessorDetails:
version = '0.0.1-SNAPSHOT'
description = '''
'''
tags = []
dependencies = []

def __init__(self, *args, **kwargs):
super().__init__()

def getRelationships(self) -> List[Relationship]:
'''
Register additional processor relationships.

Returns:
list(Relationship)
'''
return []

def getPropertyDescriptors(self) -> List[PropertyDescriptor]:
'''
Register property descriptor required to successfully run the
processor.

Returns:
list(PropertyDescriptor)
'''
return []

def onScheduled(self, context: ProcessContext) -> None:
'''
The onScheduled method in Apache NiFi is a life-cycle method that is
called when a processor is scheduled to run, allowing for
initialization tasks such as setting up resources, loading
configurations, or validating properties.

Parameters:
context (ProcessContext)

Return:
None
'''
pass

def onStopped(self, context: ProcessContext) -> None:
'''
The `onStopped` method in Apache NiFi is a life-cycle method invoked
when a processor is stopped. It is used to perform cleanup tasks, such
as releasing resources or closing connections.

Parameters:
context (ProcessContext)

Returns:
None
'''
pass

def create(self, context: ProcessContext) -> FlowFileSourceResult:
'''

Parameters:
context (ProcessContext)

Returns:
FlowFileSourceResult
'''
return FlowFileSourceResult("success")