简体   繁体   中英

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). 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.
    • Downsides: own endpoint that has to be noted down somewhere in main project, own repository: not in the other Node.js cloud functions
  2. Call python script in Node.js cloud function (like this )
    • 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?)
  3. Totally independent microservice just taking the file, analysing it and sending back JSON. Maybe as 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. The firebase CLI can then take over all the URL endpoint handling etc. But I don't see a way to do this.

A kind of better capsulated approach would be to go with 1. or 3. and have a Node.js cloud function calling the endpoint. 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. It's very easy to deploy the dockerized flask server on Cloud Run. Also it's possible to control access and authentication from the firebase function to the Cloud Run container with Google's IAM.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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