How to Export Quizzes and Flashcards as Structured JSON or Markdown in notebooklm-py

The notebooklm-py library provides native CLI commands and Python API methods to export quizzes and flashcards as structured JSON, formatted Markdown, or raw HTML by extracting embedded data from interactive artifacts.

The notebooklm-py client library enables programmatic access to Google's NotebookLM service, including robust export capabilities for generated study materials. When you need to archive or repurpose AI-generated quizzes and flashcards outside the web interface, the library offers both command-line convenience and flexible Python APIs to extract these artifacts in machine-readable JSON or human-readable Markdown formats.

CLI Commands for Exporting Artifacts

The command-line interface provides first-class support for downloading study materials through the download command group defined in src/notebooklm/cli/download.py (lines 15-24). Both download quiz and download flashcards commands accept a --format argument that controls whether you receive raw JSON, rendered Markdown, or the original HTML container.

Export Quizzes to JSON or Markdown

By default, the CLI exports the raw structured data as JSON. The command resolves the current notebook (or the one specified with -n), locates the most recently completed quiz, and writes the extracted payload to your target file.


# Export as JSON (default)

notebooklm download quiz quiz.json

# Export as formatted Markdown

notebooklm download quiz --format markdown quiz.md

When requesting Markdown, the internal _format_quiz_markdown routine (implemented in src/notebooklm/_artifacts.py, lines 88-102) transforms the JSON structure into a human-readable document containing headings, question text, answer options with checked boxes indicating correct answers, and optional hints.

Export Flashcards in Multiple Formats

Flashcard decks follow the same pattern but use the download flashcards subcommand. You can access the original interactive HTML for browser viewing, or extract the structured data for processing in other applications.


# Export as Markdown for study notes

notebooklm download flashcards --format markdown cards.md

# Export as HTML for browser viewing

notebooklm download flashcards --format html cards.html

The _format_flashcards_markdown function (lines 105-119 in src/notebooklm/_artifacts.py) handles the conversion of flashcard JSON into Markdown format with front/back card representations.

How the Export Pipeline Works

The export flow follows a consistent pipeline from user interface to file output. Understanding this architecture helps when extending the library or troubleshooting export issues.

CLI Entry Points — Commands in src/notebooklm/cli/download.py delegate to the shared helper _download_interactive (lines 67-84), which resolves the notebook reference, selects the requested artifact, and invokes the appropriate client method.

Client Methods — The src/notebooklm/_artifacts.py module implements download_quiz (lines 70-78) and download_flashcards (lines 95-103). Both functions forward to _download_interactive_artifact, passing "quiz" or "flashcards" as the artifact_type argument along with the requested output format.

Data Extraction — The _download_interactive_artifact routine performs an RPC call using the GET_INTERACTIVE_HTML method (defined in src/notebooklm/rpc/types.py, line 50) to fetch the HTML representation of the artifact. It then extracts the embedded JSON payload from the data-app-data attribute via _extract_interactive_app_data.

Type Discrimination — The system distinguishes artifact types using the ArtifactType enum in src/notebooklm/types.py (lines 98-112). Variant code 2 corresponds to quizzes, while variant 1 identifies flashcard decks. This mapping ensures the correct RPC request structure and artifact resolution logic.

Format Selection — If the user requests JSON, the raw dictionary writes directly to the target file. If Markdown is requested, the appropriate formatting helper converts the structure before writing. The HTML option preserves the original interactive container for browser-based viewing.

Programmatic Export with the Python API

For automation workflows or integration with study applications, the Python API exposes the same functionality through async methods on the NotebookLMClient class.

import asyncio
from notebooklm import NotebookLMClient, AuthTokens

async def export_quiz(notebook_id: str, out_path: str, fmt: str = "json"):
    # Load stored auth tokens (adjust path as needed)

    cookies = load_auth_from_storage()
    csrf, session_id = await fetch_tokens(cookies)
    auth = AuthTokens(cookies=cookies, csrf_token=csrf, session_id=session_id)

    async with NotebookLMClient(auth) as client:
        # Resolve the notebook ID (in case an alias was used)

        nb_id = await client.notebooks.resolve(notebook_id)
        # Download the latest completed quiz

        result_path = await client.artifacts.download_quiz(
            nb_id, out_path, output_format=fmt
        )
        print(f"Quiz saved to {result_path}")

# Run the coroutine

asyncio.run(export_quiz("my-notebook-id", "my_quiz.md", fmt="markdown"))

This programmatic approach mirrors the CLI logic exactly: download_quiz calls _download_interactive_artifact, which handles the JSON extraction and optional Markdown rendering before returning the final file path.

Summary

  • notebooklm download quiz and notebooklm download flashcards provide command-line access to export functionality defined in src/notebooklm/cli/download.py.
  • Supported output formats include JSON (default), Markdown, and HTML, controlled via the --format flag.
  • Core implementation resides in src/notebooklm/_artifacts.py, with download_quiz (lines 70-78) and download_flashcards (lines 95-103) delegating to _download_interactive_artifact.
  • Markdown formatting uses dedicated helpers: _format_quiz_markdown (lines 88-102) and _format_flashcards_markdown (lines 105-119).
  • The ArtifactType enum in src/notebooklm/types.py distinguishes quizzes (variant 2) from flashcards (variant 1).
  • All export methods extract structured data from the data-app-data attribute of HTML fetched via the GET_INTERACTIVE_HTML RPC method.

Frequently Asked Questions

What file formats does notebooklm-py support for quiz and flashcard export?

The library supports three output formats: JSON for raw structured data, Markdown for human-readable study documents with proper formatting, and HTML for the original interactive artifact container. Specify your preference using the --format flag in the CLI or the output_format parameter in the Python API.

How does notebooklm-py extract structured data from NotebookLM artifacts?

The extraction process uses _download_interactive_artifact in src/notebooklm/_artifacts.py to fetch the HTML representation via the GET_INTERACTIVE_HTML RPC call. The helper _extract_interactive_app_data then parses the data-app-data attribute from the returned HTML to retrieve the embedded JSON payload containing the quiz questions or flashcard content.

Can I export specific quiz versions or only the most recent artifact?

According to the current implementation in src/notebooklm/cli/download.py (lines 67-84), the _download_interactive helper selects the most recent completed artifact by default. The client methods in src/notebooklm/_artifacts.py do not currently expose parameters for selecting specific historical versions of quizzes or flashcard decks.

Where are the Markdown formatting functions implemented in the codebase?

The Markdown conversion logic resides in src/notebooklm/_artifacts.py. Specifically, _format_quiz_markdown handles quiz rendering (lines 88-102) and _format_flashcards_markdown handles flashcard deck formatting (lines 105-119). These functions transform the extracted JSON structures into properly formatted Markdown documents with headers, checkboxes for correct answers, and card delineations.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →