Google Sheets is a great frontend on its own, but paired with a Python backend, it allows you to quickly get data apps up and running that are both developer and end-user friendly and that can leverage all (data science) Python packages. For the backend, you can choose anything that is able to run Python, such as Google Cloud Run and to make the integration easy, we're going to use xlwings.
xlwings is an Open Source project to automate Microsoft Excel and has recently added a server version that also works with Google Sheets. Essentially, you can replace Google Apps Script with Python. While xlwings Server is part of the PRO offering, it is source-available and free for non-commercial use.
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
xlwings for Google Sheets
1. How to build web apps with
Google Sheets and Python
Felix Zumstein
April 21, 2022
2. 2
Housekeeping
• Yes, this webinar will be recorded, and you will get an
email with the replay
• Use the chat for questions: I’ll try to answer them at the
very end of the webinar
17. 17
Apps Script Code Organization
• $ xlwings copy gs
• Put xlwings and runPython calls in a different module
18. 18
Running your Code
• Apps Script Editor
• Buttons
• Custom Menus
• Sidebar (?) - works according to docs but not for me
• Add-ons for external deployment
• Triggers (see next slide)
19. 19
Triggers
• Event Source
– Time-driven
– From spreadsheet
– From calendar
• Executions Log
– with error messages
• Email alerts on failed executions
– Immediate
– Hourly/daily/weekly digests
20. 20
Error Handling
• Raise HTTPException or use an own error class
in connection with exception_handler
• This will propagate the error to Google Sheets:
21. 21
Quotas
For Workspace accounts (consumer are lower):
• Script runtime: 6 min / execution
• Triggers: 20 /user /script
• URL Fetch POST size: 50 MB / call
• URL Fetch calls: 100,000 / day
https://developers.google.com/apps-script/guides/services/quotas
24. 24
Authentication
• Easily lock down your backend to users of your
Google Workspace domain
• Use ScriptApp.getOAuthToken() as your
apiKey (OAuth2 access token)
• Google Apps Script does not contain any
sensitive token
25. 25
Authorization
• Use the authorization system that works for you:
– Define Groups via environment variables
– Use Google Directory (i.e., Groups) that comes with
Google Workspace
– Okta
– Azure AD
– LDAP
– …
26. 26
Security
• Sensitive code, data & credentials stay on the
server where they can be secured, e.g., as secrets
• In case your workbook is shared with the wrong
people, they can’t run any code
Server
• Database
credentials
• Client data
• Business logic
Short-lived access token
28. 28
Development
• Run web server locally and expose port with a
tool like ngrok
• Run in a cloud-based IDE such as GitPod or
GitHub Codespaces (no need for ngrok)
• Git push to staging server
• Maybe: Develop against local Excel installation
29. 29
Deployment
• Runs on your favorite cloud or under your desk
• Containers are ”one honking great idea”!
https://cloud.google.com/run
https://render.com
30. 30
It’s still early…
• …but sending back and forth pandas
DataFrames can often solve more issues than
many other add-ons together