如何在Nifi的虚拟环境中运行具有依赖项的python脚本? [英] How to run a python script with dependencies in a virtual environment in Nifi?

查看:78
本文介绍了如何在Nifi的虚拟环境中运行具有依赖项的python脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Nifi 有没有办法运行 Python 脚本,该脚本具有从不同文件夹导入的模块、pipfile 中指定的要求以及要传递的参数?

Is there a way in Nifi to run a python script which has modules imported from a different folder, requirements specified in a pipfile and has arguments to pass?

简而言之,如何使用Nifi执行通常在我的虚拟环境中运行的python脚本?

In short, how to execute a python script which usually runs in my virtual environment using Nifi?

我的最终目标是使用 Get File 获取文件并将其发布到 API.我试过执行进程,执行流命令处理器.

The end goal for me is to pick up a file using Get File and post it to API. I tried execute process, execute streamcommand processors.

推荐答案

要使用 Python 对流文件进行后续处理,您可以使用 ExecuteStreamCommandExecuteScript/InvokeScriptedProcessor 处理器.

To perform follow-on processing on the flowfile using Python, you can use the ExecuteStreamCommand or ExecuteScript/InvokeScriptedProcessor processors.

ExecuteStreamCommand 处理器将运行外部 shell 命令,例如 python3 my_python_script.py -arg1 string -arg2 213,它可以包装自定义 Python 代码并使用 STDIN 传递现有的流文件内容和 STDOUT 来捕获新的流文件内容.填充处理器的 Command ArgumentsCommand Path 属性以定位您的 python 可执行文件并提供 CLI 参数,包括通过 NiFi 表达式语言的流文件属性.有关示例,请参阅此答案.

The ExecuteStreamCommand processor will run an external shell command, like python3 my_python_script.py -arg1 string -arg2 213, which can wrap custom Python code and uses STDIN to pass the existing flowfile content and STDOUT to capture the new flowfile content. Populate the Command Arguments and Command Path properties of the processor to locate your python executable and provide CLI arguments, including flowfile attributes via NiFi Expression Language. See this answer for an example.

ExecuteScript 处理器运行 Jython 代码(Python 但无法访问本机库,仅兼容 Python 2.7,以及一些其他限制由于 JSR-223)在与 NiFi 相同的 JVM 中.您可以直接使用 Python 代码处理流文件属性和内容.请参阅此答案此答案 了解更多详情.

这篇关于如何在Nifi的虚拟环境中运行具有依赖项的python脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆