Scripts to:
- Enable instructors to create Google Drive folders for student teams to collaborate
- Extract Group Sets from Canvas as CSV files
python3 -m venv venv
source ./venv/bin/activate
pip install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib pandas requests google-auth
Then set up credentials. You need two kinds:
- Google OAuth Credentials, stored in
credentials.json - Canvas API Token, stored in
CANVAS_API_TOKEN
Instruction on setting those up appear below under "Set up Google Credentials"
To get a CSV of the groups that students belong to:
-
Navigate to the page where the groups are set up in Canvas, e.g. https://ucsb.instructure.com/courses/25658/groups#tab-22633
-
Get the group number from the URL in Canvas, e.g. for the url above, it's
22633 -
Set this variable in the line of code in the script
canvas_get_group_set.pyGROUP_CATEGORY_ID = "22633" # You can get this from the URL ``` -
Run the script via:
python canvas_get_group_set.py -
Your groups are now in the file
canvas_group_export.csv
To then create Google Drive folders:
- Create a top level Google Drive folder with a unique name, e.g.
CS5A-S25-ic10. - Create
Initial Contentsinside that folder and put the Jupyter notebook you want students to work with inside that folder. The script assumes thatInitial Contentswill contain a single file with the extension.ipynb - Also inside the top level folder, create a
datafolder, if desired, that will have the data files you want students to be able to access. - Set the permissions on the data file to these:

- Get the URL of the
datafolder and paste it into the Notebook inside the cells that have the!gdataline that mounts the data folder. - Run the script
python make_group_notebook_folders.py - The URLs will now be in
output_with_links.py
Preliminaries:
- Go to the Google Developer Console (https://console.cloud.google.com/)
- If you do not already have a "project", set up one (details here)
- If you do not already have an OAuth consent screen set one up(details here)
Getting credentials:
- Enable the Google Drive API:
- In the left menu, go to APIs & Services > Library.
- Search for Google Drive API and enable it.
- Create OAuth 2.0 Credentials:
- Go to APIs & Services > Credentials.
- Click Create Credentials > OAuth client ID.
- Choose Desktop App or Web Application (for local scripts, Desktop is fine).
- Download the JSON credentials file and rename it to
credentials.json. - Note that
credentials.jsonis in the.gitignoreand should not be stored in the repo
You’ll need to:
- Log into your Canvas account.
- Go to Account > Settings.
- Scroll down to "Approved Integrations" and click + New Access Token.
- Give it a name, set an expiration, and create it.
- Copy the access token (you won’t be able to see it again!).
- Store the access token in a file called
CANVAS_API_TOKEN - Note that
CANVAS_API_TOKENis in the.gitignoreand should not be stored in the Github repo.