Skip to main content

Google Classroom integration

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

ClassPackageSerializable
GoogleClassroomLoaderlangchain-google-classroom✅

Integration details

SourceDocument Lazy LoadingAsync Support
GoogleClassroomLoader✅✅

Prerequisites

To use this loader, you will need:

  1. A Google Cloud project
  2. The Classroom API enabled
  3. The Drive API enabled (for file attachments)
  4. 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-classroom

To 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)

  1. In the Google Cloud Console, create an OAuth 2.0 Client ID (Desktop application).
  2. Download the client secrets file and save it as credentials.json in your working directory.
  3. On first run, a browser window will open for user consent. The resulting token is cached to token.json for 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)

  1. In the Google Cloud Console, create a Service Account.
  2. Enable Domain-Wide Delegation for the service account.
  3. 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

ParameterTypeDefaultDescription
course_idslist[str] or NoneNoneCourse IDs to load. Loads all accessible courses when None.
load_assignmentsboolTrueLoad courseWork items.
load_announcementsboolTrueLoad announcements.
load_materialsboolTrueLoad courseWork materials.
load_attachmentsboolTrueDownload and yield Drive file attachments.
parse_attachmentsboolTrueParse 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_clstype[BaseBlobParser] or NoneNoneCustom parser class to use for attachments (replaces built-in parsers).
load_submissionsboolFalseLoad student submissions. Adds the required scope automatically.
load_topicsboolFalseLoad course topics. Adds the required scope automatically.
load_rosterboolFalseLoad student and teacher roster. Adds the required scope automatically.
load_imagesboolFalseProcess image attachments (requires a vision_model).
vision_modelBaseChatModel or NoneNoneVision-capable LLM for image understanding in PDFs and images.
max_file_sizeint50000000Maximum attachment file size in bytes. Files larger than this are skipped.
service_account_filestr or NoneNonePath to a service-account key JSON file.
token_filestr or NoneNonePath to a cached OAuth token JSON file.
client_secrets_filestr or NoneNonePath 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

FormatParserNotes
PDFPDFParserExtracts text; optional vision LLM for embedded images
DOCXDocxParserExtracts text and tables
CSVCSVParserOne document per row with header-aware formatting
Plain textTextParserUTF-8 decoding
Images (PNG, JPEG, etc.)ImageParserRequires vision_model and load_images=True
Google Docs/Sheets/SlidesExported then parsedAuto-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