Python in Google Cloud Functions - python

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

Related

Advice on Jupyter/Voila CLOUD setup

I have currently my anaconda setup on my local machine. I use standard Jupyter Notebooks (Python 3) and Voila - additionally I access DropBox where I have stored my data. It all works nice however I am thinking about moving to the cloud to do my analyzes anywhere.
I have tried Microsoft Azure and Google.
Somehow I think Azure is the better choice for me. Do you have any advice what else I should try or how to best setup Azure (I struggle - where is Voila...).
Thanks for all the hints.

Running Python Backend Firebase

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.

Firebase Cloud Functions running a python script - needs dependencies

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.

Using Compute module in "Google Cloud Client Library for Python"

I am looking at using google cloud python SDKs to manage my resources. I am not able to find compute module in the python SDK.
Python Doc here: https://googlecloudplatform.github.io/google-cloud-python/latest/
However compute module is available in Node.js SDK.
Node.js Doc here: https://googlecloudplatform.github.io/google-cloud-node/#/docs/google-cloud/0.56.0/compute
Can I get information if this module(compute) is available in python?
If not is this being planned and when can I expect it.
The google-cloud-python project you link to is hand-crafted pythonic libraries for GCP APIs. There is not yet one for Compute.
Instead you will have to use the auto-generated Python client library. See https://cloud.google.com/compute/docs/tutorials/python-guide for an example.

libspotify Python package for calling Spotify api?

I'm building an app that needs to get artwork information out of the libspotify Spotify API.
I'm building the app in python on google appengine. Does anyone know of a package that will enable me to access the libspotify API? The official page is C and I've googled around to try and find a suitable wrapper but can't seem to find one.
Thanks
Tom
There is also https://github.com/mopidy/pyspotify which is actively used in some applications and up to date.
I don't think you will be able to call libspotify at all. From the docs:
"The Python interpreter runs in a secured "sandbox" environment to isolate your application for service and security. The interpreter can run any Python code, including Python modules you include with your application, as well as the Python standard library. The interpreter cannot load Python modules with C code; it is a "pure" Python environment."
Check Spotimeta
http://pypi.python.org/pypi/spotimeta/

Categories

Resources