Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trigger python code from Google spreadsheets?

In excel you can create user defined functions with python using pyxll. I have been moving to Google spreadsheets and using their Google app script, but the libraries are so much bigger and better in python, I wish there was a way to build user defined functions using python from Google spreadsheets. There are ways to interact python with Google sheets like gspread. Is there a way to run python on Google app engine then get sheet to trigger that code? What other ways is there to trigger python code from Google spreadsheets?

like image 636
jason Avatar asked Apr 08 '14 02:04

jason


2 Answers

You should create a webservice in GAE which then can be called using Google Apps Script UrlFetch class. This is how I usually do to integrate a third party app with Apps Script App.

In a Spreadsheet container script you can create a code like

function myFunction(){
  //your code
  //Call the webservice
 var response = UrlFetchApp.fetch('my_webservice_url', {payload:'...', method:'POST'});
 Logger.log(response.getContentText());
 // your code based on response
}

Above code can be triggered by a time driven trigger in Apps Script based on some conditions

like image 145
Waqar Ahmad Avatar answered Sep 24 '22 23:09

Waqar Ahmad


Deploy your python code as a cloud function: https://cloud.google.com/functions/docs/writing/http.

Then call your function with URL Fetch as shown above.

like image 38
kjmerf Avatar answered Sep 24 '22 23:09

kjmerf