简体   繁体   English

在 Firebase 项目中使用 python 库的最佳方法

[英]Best way to use python library in Firebase project

I found a python package that I want to use within my angular based firebase project (it does some complex analysation of a text file). I found a python package that I want to use within my angular based firebase project (it does some complex analysation of a text file). What is the best way to use it?使用它的最佳方法是什么? I see the following options:我看到以下选项:

  1. Own docker container with flask, running in Cloud run (eg like that ) - pass file in AJAX request, return JSON result. Own docker container with flask, running in Cloud run (eg like that ) - pass file in AJAX request, return JSON result.
    • Downsides: own endpoint that has to be noted down somewhere in main project, own repository: not in the other Node.js cloud functions缺点:必须在主项目的某处记下自己的端点,自己的存储库:不在其他 Node.js 云函数中
  2. Call python script in Node.js cloud function (like this )在 Node.js 云 function 中调用 python 脚本(像这样
    • a little bit hacky piping file and log outputs as strings, probably not easy to get all the python dependencies working (would this work at all?)有点 hacky 管道文件和日志输出作为字符串,可能不容易让所有 python 依赖项工作(这会工作吗?)
  3. Totally independent microservice just taking the file, analysing it and sending back JSON.完全独立的微服务只是获取文件,分析它并发回 JSON。 Maybe as AWS lambda?也许是 AWS lambda?
    • again "cut out" of the main project再次“删减”主项目

I'd love to have a "clean and easy" integration in my existing Node.js cloud functions that I use in firebase.我希望在我在 firebase 中使用的现有 Node.js 云函数中进行“干净和简单”的集成。 The firebase CLI can then take over all the URL endpoint handling etc. But I don't see a way to do this.然后 firebase CLI 可以接管所有 URL 端点处理等。但我看不到这样做的方法。

A kind of better capsulated approach would be to go with 1. or 3. and have a Node.js cloud function calling the endpoint.一种更好的封装方法是对 go 和 1. 或 3. 有一个 Node.js 云 function 调用端点。 With that I would also not have the client code call the endpoint and have better possibilites in configuring it without having to update the client code.这样我也不会让客户端代码调用端点,并且在配置它时有更好的可能性,而无需更新客户端代码。

Am I missing an approach?我错过了一种方法吗? What would be the best way to do this?最好的方法是什么?

Use Case: User uploads file, the file and some other values are saved to his account.用例:用户上传文件,文件和其他一些值保存到他的帐户。 The content of the file should be analysed (can be done asynchronously) and the results should be available for the user to be shown.应该分析文件的内容(可以异步完成)并且结果应该可供用户显示。

I went with option 1 and it is working quite well so far.我选择了选项 1,到目前为止效果很好。 It's very easy to deploy the dockerized flask server on Cloud Run.在 Cloud Run 上部署 dockerized flask 服务器非常容易。 Also it's possible to control access and authentication from the firebase function to the Cloud Run container with Google's IAM.此外,还可以使用 Google 的 IAM 控制从 firebase function 到 Cloud Run 容器的访问和身份验证。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM