Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python in Google Cloud Functions

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.

like image 309
Sean Avatar asked Feb 13 '18 17:02

Sean


People also ask

Can I run Python on Google Cloud?

Google Cloud lets you choose the best environment to run your Python applications, with options for serverless, Kubernetes, VMs, or custom hardware.


4 Answers

Python 3.7 is supported now.
Steps to create one via the google cloud console:

  1. go to google cloud functions in the google cloud console and click on create function enter image description here

2.specify the function's properties enter image description here

  1. select trigger enter image description here

4.change runtime to python 3.7 enter image description here

  1. enter your cloud function logic and entry point enter image description here

  2. enter python dependencies in requirements.txt enter image description here

like image 68
Adarsh Avatar answered Oct 10 '22 18:10

Adarsh


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.

like image 20
Murtaza Kanchwala Avatar answered Oct 10 '22 16:10

Murtaza Kanchwala


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.

like image 11
arudzinska Avatar answered Oct 10 '22 18:10

arudzinska


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

like image 1
Loyal_Burrito Avatar answered Oct 10 '22 16:10

Loyal_Burrito