本页还没有译文
本页 44 段还没译成简体中文,下面显示的是英文原文。Google Classroom integration
还没翻译译自英文(docs.langchain.com)本页 44 段都还没译
Google 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.
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 and converts each item into a LangChain Document.
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.
Learn more about the package on GitHub.
Overview
| Class | Package | Serializable |
|---|---|---|
GoogleClassroomLoader | langchain-google-classroom | ✅ |
Integration details
| Source | Document Lazy Loading | Async Support |
|---|---|---|
GoogleClassroomLoader | ✅ | ✅ |
Prerequisites
To use this loader, you will need:
- A Google Cloud project
- The Classroom API enabled
- The Drive API enabled (for file attachments)
- One of the following authentication methods:
- OAuth 2.0 credentials—for personal Google accounts or testing
- Service Account credentials—for Google Workspace domains (production)
Installation
Install the integration package:
pip install -qU langchain-google-classroomTo enable parsing of PDF and DOCX attachments, install with the optional parsers extra:
pip install -qU "langchain-google-classroom[parsers]"Credentials
Option A: OAuth 2.0 (personal accounts)
- In the Google Cloud Console, create an OAuth 2.0 Client ID (Desktop application).
- Download the client secrets file and save it as
credentials.jsonin your working directory. - On first run, a browser window will open for user consent. The resulting token is cached to
token.jsonfor subsequent runs.
from langchain_google_classroom import GoogleClassroomLoader
loader = GoogleClassroomLoader()
# Opens browser for OAuth consent on first run
docs = loader.load()Option B: Service Account (Google Workspace)
- In the Google Cloud Console, create a Service Account.
- Enable Domain-Wide Delegation for the service account.
- Download the key file and save it as
service_account.json.
from langchain_google_classroom import GoogleClassroomLoader
loader = GoogleClassroomLoader(
service_account_file="service_account.json",
)
docs = loader.load()Instantiation
from langchain_google_classroom import GoogleClassroomLoader
loader = GoogleClassroomLoader(
course_ids=["123456789"], # Optional: specific courses. Loads all if omitted.
load_assignments=True, # courseWork items (default: True)
load_announcements=True, # announcements (default: True)
load_materials=True, # courseWorkMaterials (default: True)
load_attachments=True, # resolve Drive file attachments (default: True)
)Constructor parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
course_ids | list[str] or None | None | Course IDs to load. Loads all accessible courses when None. |
load_assignments | bool | True | Load courseWork items. |
load_announcements | bool | True | Load announcements. |
load_materials | bool | True | Load courseWork materials. |
load_attachments | bool | True | Download and yield Drive file attachments. |
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). |
file_parser_cls | type[BaseBlobParser] or None | None | Custom parser class to use for attachments (replaces built-in parsers). |
load_submissions | bool | False | Load student submissions. Adds the required scope automatically. |
load_topics | bool | False | Load course topics. Adds the required scope automatically. |
load_roster | bool | False | Load student and teacher roster. Adds the required scope automatically. |
load_images | bool | False | Process image attachments (requires a vision_model). |
vision_model | BaseChatModel or None | None | Vision-capable LLM for image understanding in PDFs and images. |
max_file_size | int | 50000000 | Maximum attachment file size in bytes. Files larger than this are skipped. |
service_account_file | str or None | None | Path to a service-account key JSON file. |
token_file | str or None | None | Path to a cached OAuth token JSON file. |
client_secrets_file | str or None | None | Path to an OAuth client-secrets JSON file. |
Load documents
Use load() to fetch all documents at once:
from langchain_google_classroom import GoogleClassroomLoader
loader = GoogleClassroomLoader(
course_ids=["123456789"],
)
docs = loader.load()
print(f"Loaded {len(docs)} documents")Each Document has structured page_content and rich metadata:
doc = docs[0]
print(doc.page_content[:200])
print(doc.metadata)# Example metadata
{
"source": "google_classroom",
"content_type": "assignment",
"course_id": "123456789",
"course_name": "Introduction to Computer Science",
"title": "Week 3: Data Structures",
"created_time": "2025-03-15T10:30:00.000Z",
"updated_time": "2025-03-15T10:30:00.000Z",
"alternate_link": "https://classroom.google.com/...",
}Lazy loading
For large courses or memory-constrained environments, use lazy_load() to stream documents one at a time:
from langchain_google_classroom import GoogleClassroomLoader
loader = GoogleClassroomLoader(
course_ids=["123456789"],
)
for doc in loader.lazy_load():
print(f"[{doc.metadata['content_type']}] {doc.metadata.get('title', '')}")Async loading
The loader supports async iteration via alazy_load():
import asyncio
from langchain_google_classroom import GoogleClassroomLoader
async def main():
loader = GoogleClassroomLoader(
course_ids=["123456789"],
)
docs = []
async for doc in loader.alazy_load():
docs.append(doc)
return docs
docs = asyncio.run(main())Loading additional data types
Student submissions
loader = GoogleClassroomLoader(
course_ids=["123456789"],
load_submissions=True,
)
docs = loader.load()
# Includes documents with content_type="submission"Topics
loader = GoogleClassroomLoader(
course_ids=["123456789"],
load_topics=True,
)
docs = loader.load()
# Includes documents with content_type="topic"Class roster (students and teachers)
loader = GoogleClassroomLoader(
course_ids=["123456789"],
load_roster=True,
)
docs = loader.load()
# Includes documents with content_type="student" and content_type="teacher"File attachment parsing
When load_attachments=True (the default), the loader resolves Google Drive file attachments on each classroom item and parses them into additional Document objects.
Supported formats
| Format | Parser | Notes |
|---|---|---|
PDFParser | Extracts text; optional vision LLM for embedded images | |
| DOCX | DocxParser | Extracts text and tables |
| CSV | CSVParser | One document per row with header-aware formatting |
| Plain text | TextParser | UTF-8 decoding |
| Images (PNG, JPEG, etc.) | ImageParser | Requires vision_model and load_images=True |
| Google Docs/Sheets/Slides | Exported then parsed | Auto-exported to PDF/CSV/plain text via Drive API |
Using a vision LLM for images
To process image attachments and extract visual context from PDF pages, provide a vision-capable model:
from langchain_google_genai import ChatGoogleGenerativeAI
from langchain_google_classroom import GoogleClassroomLoader
loader = GoogleClassroomLoader(
course_ids=["123456789"],
load_attachments=True,
load_images=True,
vision_model=ChatGoogleGenerativeAI(model="gemini-2.0-flash"),
)
docs = loader.load()Using a custom file parser
You can replace the built-in parsers with any BaseBlobParser subclass:
from langchain_community.document_loaders.parsers.pdf import PyMuPDFParser
from langchain_google_classroom import GoogleClassroomLoader
loader = GoogleClassroomLoader(
course_ids=["123456789"],
file_parser_cls=PyMuPDFParser,
)
docs = loader.load()API reference
- PyPI:
langchain-google-classroom - Source: GitHub