Support Questions

Find answers, ask questions, and share your expertise

How to update FlowFile attributes in Python now that Jython is removed?

avatar
Contributor

In NiFi 2.4 and above, the Jython engine is no longer available in ExecuteScript.
Previously, I used scripts like this to read and update attributes:

val = flowFile.getAttribute('x')
flowFile = session.putAttribute(flowFile, 'x', str(int(val) + 10))

Now I want to do the same using Python in NiFi 2.4+:

  • Read an attribute (e.g., x)

  • Compute a new value

  • Write it back as an attribute (or a new one)

  • Keep the original FlowFile content unchanged

What’s the recommended way in NiFi 2.4+?

Any official docs, samples, or best practices for this scenario would be very helpful.

3 REPLIES 3

avatar
Super Collaborator

 

In NiFi 2.4 and above, the built-in Jython (Python 2 interpreter) for ExecuteScript has been removed, so the traditional approach using inline Python is no longer supported. There is, however, a modern and robust alternative using NiFi's first-class Python processor support for attribute manipulation, or using Groovy/Clojure in ExecuteScript, or simply leveraging UpdateAttribute for simple logic.

https://nifi.apache.org/nifi-docs/python-developer-guide.html
https://nifi.apache.org/components/org.apache.nifi.processors.script.ExecuteScript/

avatar
Contributor

However, I was able to resolve this by leveraging ExecuteStreamCommand (ESC). Specifically, I used the Output Destination Attribute property to push the required attributes into it, which I can then process separately.

avatar
Contributor

That approach is not feasible. Adopting a new programming language is impractical given the large number of existing Python scripts that I cannot realistically migrate. The second option is also suboptimal, since creating a dedicated NiFi processor for each script would introduce significant overhead. Furthermore, each custom processor would run in its own isolated virtual environment, leading to excessive heap consumption