A web application starter template, created in Python with the Flask framework. Allows users to login with their Google accounts (via OAuth). Interfaces with a Google Sheets database.
This application requires a Python development environment:
- Git
- Anaconda, Python, Pip
For beginners, here are some instructions for how to install Anaconda, and set up your local Python development environment.
Make a copy of this template repo (as necessary). Clone your copy of the repo onto your local machine. Navigate there from the command-line.
Setup and activate a new Anaconda virtual environment:
conda create -n gradebook-hero-env python=3.10
conda activate gradebook-hero-env
Install package dependencies:
pip install -r requirements.txt
This app requires a few services, for user authentication and data storage. Follow the instructions below to setup these services.
Visit the Google Cloud Console. Create a new project, and name it. After it is created, select it from the project selection dropdown menu.
Visit the API Credentials page for your Google Cloud project. Click the button with the plus icon to "Create Credentials", and choose "Create OAuth Client Id".
Click to "Configure Consent Screen". Leave the domain info blank, and leave the defaults / skip lots of the setup for now. If/when you deploy your app to a production server, you can return to populating this info (or you will be using a different project).
Return to actually creating the "OAuth Client Id". Choose a "Web application" type, give it a name, and set the following "Authorized Redirect URIs" (for now, while the project is still in development):
After the client is created, note the GOOGLE_CLIENT_ID
and GOOGLE_CLIENT_SECRET
, and set them as environment variables (see configuration section below).
To fetch data from the Google Sheets database (and use other Google APIs), the app will need access to a local "service account" credentials file.
From the Google API Credentials page, create a new service account as necessary.
For the chosen service account, create new JSON credentials file as necessary from the "Keys" menu, then download the resulting JSON file into the root directory of this repo, specifically named "google-credentials.json".
See the Google Sheets Database Setup guide.
If you would like to configure Google Analytics, consult the Google Analytics Setup guide.
Create a file called ".env" in the root directory of this repository, and populate it with environment variables to specify your own credentials, as obtained in the "Setup" section above:
FLASK_APP="web_app"
#
# GOOGLE OAUTH
#
GOOGLE_CLIENT_ID="____________"
GOOGLE_CLIENT_SECRET="____________"
#
# GOOGLE SHEETS DATABASE
#
#GOOGLE_SHEETS_DOCUMENT_ID="____________"
#
# GOOGLE ANALYTICS
#
#GA_TRACKER_ID="UA-XXXXXXX-1"
After configuring the Google Sheet database and populating it with products, you should be able to test out the app's ability to fetch products (and generate new orders):
python -m app.spreadsheet_service
Run the local web server (then visit localhost:5000 in a browser):
FLASK_APP=web_app flask run
Run tests:
pytest
NOTE: we are using a live sheet for testing, so to avoid API rate limits, we are waiting / sleeping between each test, which makes the tests a bit slow for now
See more information about the CI build process.
See the Deployer's Guide for instructions on deploying to a production server hosted by Render.