This project hosts web applications that demonstrate the implmentation of a Google Classroom add-on using Python. Current examples use the Flask framework.
These examples are intended to accompany the guided walkthroughs on the Classroom Add-ons developer site. Please refer to the site for implementation details.
- Python 3.7+
-
Create a Google Cloud Platform (GCP) project. Enable the following in the API Library:
Visit the developer site for configuration instructions for the GWM SDK. You will also need to install the add-on for it to be visible in Google Classroom.
-
Visit your project's Credentials page. Create two credentials in the project:
- An API Key. You can leave it as Unrestricted for the purposes of these examples.
- An OAuth client ID.
- The application type should be Web application.
- Add
<your server>/callbackas an Authorized redirect URI. For example,https://localhost:5000/callback
Return to the Credentials page once both have been created, then:
- Copy your API Key and assign it to the environment variable
GOOGLE_API_KEY:export GOOGLE_API_KEY=YOUR_COPIED_API_KEY - Download the OAuth2 client credentials as JSON.
-
Install Python 3.7+ and ensure that
pipis available:python -m ensurepip --upgrade -
Clone this repository and
cdinto the root project directory:git clone https://github.com/googleworkspace/python-classroom-addon cd python-classroom-addon -
(Optional, but recommended!) Set up and activate a new Python virtual environment in the python-classroom-addon directory:
python3 -m venv .classroom-addon-env source .classroom-addon-env/bin/activateWhen finished, use the
deactivatecommand in your shell to exit the virtual environment. -
cdinto an example directory:cd flask/01-basic-app -
Install the required libraries using
pip:pip install -r requirements.txt -
Inspect the
main.pyfile and enable one option for running a server. For example, to run the web app onlocalhost:if __name__ == "__main__": ### OPTION 1: Unsecured localhost os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1" # Run the application on http://localhost:5000. app.run(debug=True)
-
Launch the server by running the
main.pyfile:python main.py -
To load your app, either open the app in your browser or select your application in the Add-ons menu when creating an Assignment in Google Classroom.