Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

How can we read a flowfile content with a python script ?

avatar
Contributor

the example is the next:

Ghilani_0-1671195696165.png

GenerateFlowFile content:

Ghilani_1-1671195844692.png

I want to clean the ETX character with a python script (Nifi wasn't able to clean it with replaceText), so I decided to pass the list to a python script to clean it, but am not sure how to read the Flowfile content. 

Ghilani_2-1671196414290.png

The list (my_list) should be passed as Flowfile to the python script.

2 REPLIES 2

avatar
Super Collaborator

avatar

@Ghilani You should know these 3 articles intimately if you want to use Execute Script

 

https://community.cloudera.com/t5/Community-Articles/ExecuteScript-Cookbook-part-1/ta-p/248922

https://community.cloudera.com/t5/Community-Articles/ExecuteScript-Cookbook-part-2/ta-p/249018

https://community.cloudera.com/t5/Community-Articles/ExecuteScript-Cookbook-part-3/ta-p/249148

 

 

That said, it's sometimes helpful for me to see a working example and modify from there.  As such, here is a github with a sample flow definition file (01_Fraud_Detection_Demo_Params_ExecuteScript.json) and script file(Fraud Demo ExecuteScript.py) that should work out of the box:

 

https://github.com/cldr-steven-matison/Fraud-Prevention-With-Cloudera-SSB/tree/main/Templates

 

Pay attention to imports and, then line 160 is what you want to get the flowfile.   My flow ignores the content, but you should be able to find references in the Part 1 cookbook for anything you want to do w/ flowfile content.