I am new to using firebase so I was looking to see if it was possible to call a python script in firebase to manipulate an image.
I have already written a python program that takes an input image and processes it and returns a new image. I would like to extend this where a mobile or web app could send a user-provided image, to the database, the python program would run and the app would show the processed image.
I assume that a REST API could handle this but my question is if I could run the python script over the cloud. I know firebase has a cloud run function but I have never touched it. Please let me know if there are any resources for this or any alternatives.
Although Firebase Functions can be written only in JS or TS they are part of Google Cloud Function. If you create the function in Firebase you will see it as well in Functions in Google Cloud Console.
So it's practically the same feature, however GCP gives you possibility to write cloud functions in many languages (currently 7, I think). Among them you can use Python
in version 3.7, 3.8 and 3.9 (currently in beta).
You can use GCP GUI to write the functions or use Cloud SDK (gcloud functions deploy) to create the function. Nice examples are in mentioned documentation.
Additionally the Cloud Function has nice choice of triggers including Firebase related.
Related
I have python code that uses Gmail API for fetching unread emails and adding labels according to some rules.
The code runs on my computer and I wish to create a Gmail add-on for this labeling, the add-on should include a new button in the Gmail interface.
The problem is that Google add-on uses google app script.
I want to ask if there is a possibility to embed my python code into the google app script?
Thanks :)
You might use Python with Google Apps Script API to programmatically create and modify a Google Apps Script project, but the Google Apps Script uses V8 as it's runtime, and it requires JavaScript.
You might use Google Cloud Run (see https://cloud.google.com/run/docs/quickstarts/build-and-deploy/deploy-python-service) or another hosting infrastructure to use Python to use the Card Service to build the add-on user interface and use the Gmail API.
I think that it might be possible to use Google Colaboratory as the hosting infrastructure but I have no idea how convenient it will be compared to use Google Cloud Run.
I'm building a website with React and Firebase that utilizes an algorithm I wrote in python. The database and authentication for the project are both handled by Firebase, so I would like to keep the cloud functions in that same ecosystem if possible.
Right now, I'm using the python-shell npm package to send and receive data from NodeJS to my python script.
I have local unit testing set up so I can test the https.onCall functions locally without needing to deploy and test from the client.
When I am testing locally, everything works perfectly.
However, when I push the functions to the cloud and trigger the function from the client, the logs in the Firebase console show that the python script is missing dependencies.
What is the best way to ensure that the script has all the dependencies available to it up on the server?
I have tried:
-Copying the actual dependency folders from my library/.../site-packages and putting them in the same directory under the /functions folder with the python script. This almost works. I just run into an issue with numpy: "No module named 'numpy.core._multiarray_umath'" is printed to the logs in Firebase.
I apologize if this is an obvious answer. I'm new to Python, and the solutions I've found online seem way to elaborate or involve hosting the python code in another ecosystem (like AWS or Heroku). I am especially hesitant to go to all that work because it runs fine locally. If I can just find a way to send the dependencies up with the script I'm good to go.
Please let me know if you need any more information.
the logs in the Firebase console show that the python script is missing dependencies.
That's because the nodejs runtime targeted by the Firebase CLI doesn't have everything you need to run python programs.
If you need to run a function that's primarily written in python, you should not use the Firebase CLI and instead uses the Google Cloud tools to target the python runtime, which should do everything you want. Yes, it might be extra work for you to learn new tools, and you will not be able to use the Firebase CLI, but it will be the right way to run python in Cloud Functions.
We are using GCP's Firebase with Firestore for a new mobile app we are developing. As part of this effort we need to deploy a number of cloud functions which will act as Firestore triggers for doing some back end processing.
Our intention is to keep the deploys encapsulated inside of Firebase by using the firebase cli tools. However when we attempt to initiate the Firebase project for functions using the "firebase init functions" call the only two language options are "Javascript" and "Typescript", and the only deployable stack seems to be Node.js.
On previous GCP projects we had deployed Python based cloud functions (using the gcloud cli) and ideally we'd like to continue using Python for our Firebase cloud functions. So my questions are:
is it possible to deploy Python-based Firebase cloud functions? If not:
can we simply go back to deploying Python-based GCP cloud functions using the gcloud cli and still have them work as Firestore triggers?
Thanks
The Firebase CLI does not support deploying functions written in python.
You can certainly write Cloud Firestore triggers in python and deploy them with gcloud.
One thing you might not be aware of: the underlying Cloud Functions product is the same no matter how you deploy your functions. Firebase just adds tools and APIs on top of the existing Google Cloud Functions infrastructure. There is really no such thing as a "Firebase Cloud Function". There is just Cloud Functions, and you have options about how you can write and deploy them, either using gcloud, or the Firebase CLI.
Can Google Cloud Functions handle python with packages like sklearn, pandas, etc? If so, can someone point me in the direction of resources on how to do so.
I've been searching a while and it seems like this is impossible, all I've found are resources to deploy the base python language to google cloud.
Python 3.7 is supported now.
Steps to create one via the google cloud console:
go to google cloud functions in the google cloud console and click on create function
2.specify the function's properties
select trigger
4.change runtime to python 3.7
enter your cloud function logic and entry point
enter python dependencies in requirements.txt
EDIT: As of July 2018 there is now a Python runtime (3.7) available for Google Cloud Functions!
OLD ANSWER: Google Cloud Functions (GCF) are written in JavaScript (executed in a Node.js runtime), so there is no way for them to actually handle Python at this moment. There is a Python module at GitHub that you might have come across and it can be used to write and deploy GCF with one of three trigger types: http, Pub/Sub and bucket. The module takes care of translating your Python logic to a JavaScript code that is later run inside Google Cloud Platform.
When it comes to other packages like pandas, the ‘translation’ into JavaScript was not prepared for them by anyone AFAIK. If you really don’t like the idea of jumping into JavaScript and writing the Cloud Function code on your own (with the logic you intended to use in a Python script), you have a possible workaround. You can evoke your Python script from inside of the Cloud Function written in JS - the idea was discussed in this topic. Another way is using Object Change Notifications or Pub/Sub Notifications as explained here.
As of 19th July 2018, Google Cloud Functions supports Python 3.7.
Kindly check the Runtime environment to find the Python 3.7 runtime and sample script (based on Flask) .
--UPDATED--
Official Documentation for the Google Cloud Functions - Python 3.7 support Beta Release.
This is a beta release of the Python runtime for Google Cloud
Functions. This feature might be changed in backward-incompatible ways
and is not subject to any SLA or deprecation policy.
SkLearn, Numpy is supported in Google Cloud function. Also I've run a sample test to confirm the availability of Pandas as well and its working fine.
https://github.com/mkanchwala/google-functions-python-example
Hope this helps to all the "Py" lovers.
You can use AWS lambda as well if you want to work around and still use Python as your main language. Some modules/packages will need to be imported via zip file with AWS Lambda but it has a broader range of usable languages than GCF
As a Python project, I would like to control Google Hangouts (start/end video/phone calls, mute/unmute, dial a key, etc) using Python 2.7; e.g. create a call() function that accepts email addresses and phone numbers of people in my circles/contacts and call those people.
As a newbie, however, I don't know whether:
There is already a Python package that does (most of) that,
I need to sign up for Google Cloud, install Google Cloud SDK, learn
how to use the Google App Engine, etc. or just being logged into Google in a browser is sufficient
So, I'd appreciate if someone could sketch a brief road map for me.
For example, what Python packages do I need?
Hangups, a python instant messaging client for hangouts already exists and is probably worth a look. It's a terminal client, but it is also used as a back-end for several GUI applications.
https://github.com/tdryer/hangups