Using Script to Integrate Custom CodePDF version

Using a Python processor

Python processors in MiNiFi C++ are loaded from external files, and they keep running a function, while retaining the interpreter state. This makes them well-suited for tasks that require maintaining state between runs or executing initialization logic to be run only once. Learn how to integrate custom code seamlessly into a MiNiFi C++ agent by utilizing custom Python processors. You can unlock the full potential of your MiNiFi C++ Agent by enhancing its functionality with the flexibility offered by Python processors.

The workflow of a Python processor:
  1. At startup, the MiNiFi C++ agent reads the Python script directory specified in the minifi.properties file as the value of the nifi.python.processor.dir property. By default, this directory is set to MINIFI_HOME/minifi-python.
  2. The agent scans the directory for compatible scripts and automatically registers them for use.
  3. Python files are evaluated during startup. Their onSchedule function is invoked before starting a flow and their onTrigger function is called regularly as the processor is scheduled.
For more details, see the following example:
#!/usr/bin/env python
def describe(processor):
    processor.setDescription("Adds an attribute to your flow files")


def onInitialize(processor):
    processor.setSupportsDynamicProperties()


def onTrigger(context, session):
    flow_file = session.get()
    if flow_file is not None:
        flow_file.addAttribute("Python attribute", "attributevalue")
    session.transfer(flow_file, REL_SUCCESS)

To add or update processors, place the Python files in the designated script directory and restart the agent.

We want your opinion

How can we improve this page?

What kind of feedback do you have?