|
| 1 | +--- |
| 2 | +title: "Google Classroom integration" |
| 3 | +description: "Integrate with the Google Classroom document loader using LangChain Python." |
| 4 | +--- |
| 5 | + |
| 6 | +> [Google Classroom](https://edu.google.com/workspace-for-education/classroom/) is a free learning management system developed by Google as part of Google Workspace for Education. It helps educators manage coursework, assignments, and communication. |
| 7 | +
|
| 8 | +This page covers how to load data from Google Classroom using the `GoogleClassroomLoader`. The loader fetches courses, assignments (courseWork), announcements, course materials, student submissions, rubrics, topics, and class rosters from the [Classroom API](https://developers.google.com/classroom) and converts each item into a LangChain `Document`. |
| 9 | + |
| 10 | +When file attachments are present on classroom items, the loader automatically downloads and parses them from Google Drive—supporting PDF, DOCX, CSV, plain text, Google Docs, Sheets, Slides, and images. |
| 11 | + |
| 12 | +Learn more about the package on [GitHub](https://github.com/ayanokojix21/langchain-google-classroom). |
| 13 | + |
| 14 | +## Overview |
| 15 | + |
| 16 | +| Class | Package | Serializable | |
| 17 | +|:------|:--------|:-------------| |
| 18 | +| `GoogleClassroomLoader` | [`langchain-google-classroom`](https://pypi.org/project/langchain-google-classroom/) | ✅ | |
| 19 | + |
| 20 | +### Integration details |
| 21 | + |
| 22 | +| Source | Document Lazy Loading | Async Support | |
| 23 | +|:-------|:---------------------:|:-------------:| |
| 24 | +| `GoogleClassroomLoader` | ✅ | ✅ | |
| 25 | + |
| 26 | +## Prerequisites |
| 27 | + |
| 28 | +To use this loader, you will need: |
| 29 | + |
| 30 | +1. A [Google Cloud project](https://developers.google.com/workspace/guides/create-project) |
| 31 | +2. The [Classroom API](https://console.cloud.google.com/apis/library/classroom.googleapis.com) enabled |
| 32 | +3. The [Drive API](https://console.cloud.google.com/apis/library/drive.googleapis.com) enabled (for file attachments) |
| 33 | +4. One of the following authentication methods: |
| 34 | + - **OAuth 2.0 credentials**—for personal Google accounts or testing |
| 35 | + - **Service Account credentials**—for Google Workspace domains (production) |
| 36 | + |
| 37 | +## Installation |
| 38 | + |
| 39 | +Install the integration package: |
| 40 | + |
| 41 | +```bash |
| 42 | +pip install -qU langchain-google-classroom |
| 43 | +``` |
| 44 | + |
| 45 | +To enable parsing of PDF and DOCX attachments, install with the optional `parsers` extra: |
| 46 | + |
| 47 | +```bash |
| 48 | +pip install -qU "langchain-google-classroom[parsers]" |
| 49 | +``` |
| 50 | + |
| 51 | +## Credentials |
| 52 | + |
| 53 | +### Option A: OAuth 2.0 (personal accounts) |
| 54 | + |
| 55 | +1. In the [Google Cloud Console](https://console.cloud.google.com/apis/credentials), create an **OAuth 2.0 Client ID** (Desktop application). |
| 56 | +2. Download the client secrets file and save it as `credentials.json` in your working directory. |
| 57 | +3. On first run, a browser window will open for user consent. The resulting token is cached to `token.json` for subsequent runs. |
| 58 | + |
| 59 | +```python |
| 60 | +from langchain_google_classroom import GoogleClassroomLoader |
| 61 | + |
| 62 | +loader = GoogleClassroomLoader() |
| 63 | +# Opens browser for OAuth consent on first run |
| 64 | +docs = loader.load() |
| 65 | +``` |
| 66 | + |
| 67 | +### Option B: Service Account (Google Workspace) |
| 68 | + |
| 69 | +1. In the [Google Cloud Console](https://console.cloud.google.com/iam-admin/serviceaccounts), create a Service Account. |
| 70 | +2. Enable [Domain-Wide Delegation](https://developers.google.com/identity/protocols/oauth2/service-account#delegatingauthority) for the service account. |
| 71 | +3. Download the key file and save it as `service_account.json`. |
| 72 | + |
| 73 | +```python |
| 74 | +from langchain_google_classroom import GoogleClassroomLoader |
| 75 | + |
| 76 | +loader = GoogleClassroomLoader( |
| 77 | + service_account_file="service_account.json", |
| 78 | +) |
| 79 | +docs = loader.load() |
| 80 | +``` |
| 81 | + |
| 82 | +## Instantiation |
| 83 | + |
| 84 | +```python |
| 85 | +from langchain_google_classroom import GoogleClassroomLoader |
| 86 | + |
| 87 | +loader = GoogleClassroomLoader( |
| 88 | + course_ids=["123456789"], # Optional: specific courses. Loads all if omitted. |
| 89 | + load_assignments=True, # courseWork items (default: True) |
| 90 | + load_announcements=True, # announcements (default: True) |
| 91 | + load_materials=True, # courseWorkMaterials (default: True) |
| 92 | + load_attachments=True, # resolve Drive file attachments (default: True) |
| 93 | +) |
| 94 | +``` |
| 95 | + |
| 96 | +### Constructor parameters |
| 97 | + |
| 98 | +| Parameter | Type | Default | Description | |
| 99 | +|:----------|:-----|:--------|:------------| |
| 100 | +| `course_ids` | `list[str]` or `None` | `None` | Course IDs to load. Loads all accessible courses when `None`. | |
| 101 | +| `load_assignments` | `bool` | `True` | Load courseWork items. | |
| 102 | +| `load_announcements` | `bool` | `True` | Load announcements. | |
| 103 | +| `load_materials` | `bool` | `True` | Load courseWork materials. | |
| 104 | +| `load_attachments` | `bool` | `True` | Download and yield Drive file attachments. | |
| 105 | +| `parse_attachments` | `bool` | `True` | Parse attachment content using built-in parsers (install `langchain-google-classroom[parsers]` for PDF/DOCX support, or set `parse_attachments=False` to skip parsing). | |
| 106 | +| `file_parser_cls` | `type[BaseBlobParser]` or `None` | `None` | Custom parser class to use for attachments (replaces built-in parsers). | |
| 107 | +| `load_submissions` | `bool` | `False` | Load student submissions. Adds the required scope automatically. | |
| 108 | +| `load_topics` | `bool` | `False` | Load course topics. Adds the required scope automatically. | |
| 109 | +| `load_roster` | `bool` | `False` | Load student and teacher roster. Adds the required scope automatically. | |
| 110 | +| `load_images` | `bool` | `False` | Process image attachments (requires a `vision_model`). | |
| 111 | +| `vision_model` | `BaseChatModel` or `None` | `None` | Vision-capable LLM for image understanding in PDFs and images. | |
| 112 | +| `max_file_size` | `int` | `50000000` | Maximum attachment file size in bytes. Files larger than this are skipped. | |
| 113 | +| `service_account_file` | `str` or `None` | `None` | Path to a service-account key JSON file. | |
| 114 | +| `token_file` | `str` or `None` | `None` | Path to a cached OAuth token JSON file. | |
| 115 | +| `client_secrets_file` | `str` or `None` | `None` | Path to an OAuth client-secrets JSON file. | |
| 116 | + |
| 117 | +## Load documents |
| 118 | + |
| 119 | +Use `load()` to fetch all documents at once: |
| 120 | + |
| 121 | +```python |
| 122 | +from langchain_google_classroom import GoogleClassroomLoader |
| 123 | + |
| 124 | +loader = GoogleClassroomLoader( |
| 125 | + course_ids=["123456789"], |
| 126 | +) |
| 127 | +docs = loader.load() |
| 128 | +print(f"Loaded {len(docs)} documents") |
| 129 | +``` |
| 130 | + |
| 131 | +Each `Document` has structured `page_content` and rich `metadata`: |
| 132 | + |
| 133 | +```python |
| 134 | +doc = docs[0] |
| 135 | +print(doc.page_content[:200]) |
| 136 | +print(doc.metadata) |
| 137 | +``` |
| 138 | + |
| 139 | +```python |
| 140 | +# Example metadata |
| 141 | +{ |
| 142 | + "source": "google_classroom", |
| 143 | + "content_type": "assignment", |
| 144 | + "course_id": "123456789", |
| 145 | + "course_name": "Introduction to Computer Science", |
| 146 | + "title": "Week 3: Data Structures", |
| 147 | + "created_time": "2025-03-15T10:30:00.000Z", |
| 148 | + "updated_time": "2025-03-15T10:30:00.000Z", |
| 149 | + "alternate_link": "https://classroom.google.com/...", |
| 150 | +} |
| 151 | +``` |
| 152 | + |
| 153 | +## Lazy loading |
| 154 | + |
| 155 | +For large courses or memory-constrained environments, use `lazy_load()` to stream documents one at a time: |
| 156 | + |
| 157 | +```python |
| 158 | +from langchain_google_classroom import GoogleClassroomLoader |
| 159 | + |
| 160 | +loader = GoogleClassroomLoader( |
| 161 | + course_ids=["123456789"], |
| 162 | +) |
| 163 | + |
| 164 | +for doc in loader.lazy_load(): |
| 165 | + print(f"[{doc.metadata['content_type']}] {doc.metadata.get('title', '')}") |
| 166 | +``` |
| 167 | + |
| 168 | +## Async loading |
| 169 | + |
| 170 | +The loader supports async iteration via `alazy_load()`: |
| 171 | + |
| 172 | +```python |
| 173 | +import asyncio |
| 174 | +from langchain_google_classroom import GoogleClassroomLoader |
| 175 | + |
| 176 | + |
| 177 | +async def main(): |
| 178 | + loader = GoogleClassroomLoader( |
| 179 | + course_ids=["123456789"], |
| 180 | + ) |
| 181 | + docs = [] |
| 182 | + async for doc in loader.alazy_load(): |
| 183 | + docs.append(doc) |
| 184 | + return docs |
| 185 | + |
| 186 | + |
| 187 | +docs = asyncio.run(main()) |
| 188 | +``` |
| 189 | + |
| 190 | +## Loading additional data types |
| 191 | + |
| 192 | +### Student submissions |
| 193 | + |
| 194 | +```python |
| 195 | +loader = GoogleClassroomLoader( |
| 196 | + course_ids=["123456789"], |
| 197 | + load_submissions=True, |
| 198 | +) |
| 199 | +docs = loader.load() |
| 200 | +# Includes documents with content_type="submission" |
| 201 | +``` |
| 202 | + |
| 203 | +### Topics |
| 204 | + |
| 205 | +```python |
| 206 | +loader = GoogleClassroomLoader( |
| 207 | + course_ids=["123456789"], |
| 208 | + load_topics=True, |
| 209 | +) |
| 210 | +docs = loader.load() |
| 211 | +# Includes documents with content_type="topic" |
| 212 | +``` |
| 213 | + |
| 214 | +### Class roster (students and teachers) |
| 215 | + |
| 216 | +```python |
| 217 | +loader = GoogleClassroomLoader( |
| 218 | + course_ids=["123456789"], |
| 219 | + load_roster=True, |
| 220 | +) |
| 221 | +docs = loader.load() |
| 222 | +# Includes documents with content_type="student" and content_type="teacher" |
| 223 | +``` |
| 224 | + |
| 225 | +## File attachment parsing |
| 226 | + |
| 227 | +When `load_attachments=True` (the default), the loader resolves Google Drive file attachments on each classroom item and parses them into additional `Document` objects. |
| 228 | + |
| 229 | +### Supported formats |
| 230 | + |
| 231 | +| Format | Parser | Notes | |
| 232 | +|:-------|:-------|:------| |
| 233 | +| PDF | `PDFParser` | Extracts text; optional vision LLM for embedded images | |
| 234 | +| DOCX | `DocxParser` | Extracts text and tables | |
| 235 | +| CSV | `CSVParser` | One document per row with header-aware formatting | |
| 236 | +| Plain text | `TextParser` | UTF-8 decoding | |
| 237 | +| Images (PNG, JPEG, etc.) | `ImageParser` | Requires `vision_model` and `load_images=True` | |
| 238 | +| Google Docs/Sheets/Slides | Exported then parsed | Auto-exported to PDF/CSV/plain text via Drive API | |
| 239 | + |
| 240 | +### Using a vision LLM for images |
| 241 | + |
| 242 | +To process image attachments and extract visual context from PDF pages, provide a vision-capable model: |
| 243 | + |
| 244 | +```python |
| 245 | +from langchain_google_genai import ChatGoogleGenerativeAI |
| 246 | +from langchain_google_classroom import GoogleClassroomLoader |
| 247 | + |
| 248 | +loader = GoogleClassroomLoader( |
| 249 | + course_ids=["123456789"], |
| 250 | + load_attachments=True, |
| 251 | + load_images=True, |
| 252 | + vision_model=ChatGoogleGenerativeAI(model="gemini-2.0-flash"), |
| 253 | +) |
| 254 | +docs = loader.load() |
| 255 | +``` |
| 256 | + |
| 257 | +### Using a custom file parser |
| 258 | + |
| 259 | +You can replace the built-in parsers with any `BaseBlobParser` subclass: |
| 260 | + |
| 261 | +```python |
| 262 | +from langchain_community.document_loaders.parsers.pdf import PyMuPDFParser |
| 263 | +from langchain_google_classroom import GoogleClassroomLoader |
| 264 | + |
| 265 | +loader = GoogleClassroomLoader( |
| 266 | + course_ids=["123456789"], |
| 267 | + file_parser_cls=PyMuPDFParser, |
| 268 | +) |
| 269 | +docs = loader.load() |
| 270 | +``` |
| 271 | + |
| 272 | +## API reference |
| 273 | + |
| 274 | +- **PyPI:** [`langchain-google-classroom`](https://pypi.org/project/langchain-google-classroom/) |
| 275 | +- **Source:** [GitHub](https://github.com/ayanokojix21/langchain-google-classroom) |
0 commit comments