Deploying Python Web Apps
It runs on your machine, but how do you share it with the world?
When deploying a Python app that uses Google Sheets, you need to be careful with your secrets. You can't just upload your credentials.json to GitHub!
Instead, efficient deployments use Environment Variables.
- Convert your JSON key to a string.
- Save it as a secret variable (like
G_SHEETS_CREDENTIALS) on your hosting platform (Render, Heroku, Vercel, etc.). - Update your code to read from the environment variable instead of a file.
import os
import json
json_creds = os.getenv("G_SHEETS_CREDENTIALS")
creds_dict = json.loads(json_creds)
gc = gspread.service_account_from_dict(creds_dict)
Now your app is secure and ready for the public!
I cover secure deployment strategies in depth in my Full Stack Google Sheets course.