Skip to main content

File-based Google Sheets representation library for LLM agents

Project description

extrasheet

File-based Google Sheets representation library for LLM agents.

Overview

extrasheet transforms Google Sheets into a file-based representation optimized for LLM agents. Instead of working with complex API responses, agents interact with simple files:

  • data.tsv - Cell values in tab-separated format (formulas show computed values)
  • formula.json - Sparse dictionary mapping cell coordinates to formulas
  • format.json - Cell formatting definitions
  • feature.json - Advanced features (charts, pivot tables, filters, etc.)

This separation allows LLM agents to selectively load only the data they need, reducing token usage and enabling efficient "fly-blind" editing.

Installation

pip install extrasheet

Or with uv:

uv add extrasheet

Quick Start

import asyncio
from extrasheet import SheetsClient, GoogleSheetsTransport

async def main():
    # Create transport with access token
    transport = GoogleSheetsTransport(access_token="your_token")

    # Initialize client with transport
    client = SheetsClient(transport)

    # Pull spreadsheet to local files
    files = await client.pull(
        "1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms",
        "./output",
        max_rows=100,      # Default: 100 rows per sheet
        save_raw=True,     # Default: saves raw API responses
    )

    # Clean up
    await transport.close()

asyncio.run(main())

# Files created:
# ./output/1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms/
#   ├── spreadsheet.json     # Spreadsheet metadata
#   ├── Sheet1/
#   │   ├── data.tsv         # Cell values
#   │   ├── formula.json     # Cell formulas
#   │   ├── format.json      # Cell formatting
#   │   └── feature.json     # Charts, pivot tables, etc.
#   ├── .raw/
#   │   ├── metadata.json    # Raw metadata API response
#   │   └── data.json        # Raw data API response
#   └── .pristine/
#       └── spreadsheet.zip  # Pristine copy for diff/push

CLI Usage

# Pull a spreadsheet to local files (defaults to ./<spreadsheet_id>/)
python -m extrasheet pull <spreadsheet_url_or_id> [output_dir]

# Limit rows fetched per sheet (default: 100)
python -m extrasheet pull <url> --max-rows 500

# Fetch all rows (may timeout on large spreadsheets)
python -m extrasheet pull <url> --no-limit

# Don't save raw API responses
python -m extrasheet pull <url> --no-raw

Architecture

The library uses a transport-based architecture for clean separation of concerns:

┌─────────────────┐     ┌──────────────────┐     ┌─────────────────┐
│ SheetsClient    │────▶│ Transport        │────▶│ Google API /    │
│ (orchestration) │     │ (data fetching)  │     │ Local Files     │
└─────────────────┘     └──────────────────┘     └─────────────────┘
        │
        ▼
┌─────────────────┐     ┌──────────────────┐
│ Transformer     │────▶│ FileWriter       │
│ (API → files)   │     │ (disk I/O)       │
└─────────────────┘     └──────────────────┘

Transport implementations:

  • GoogleSheetsTransport - Production transport using Google Sheets API
  • LocalFileTransport - Test transport reading from local golden files

Testing with Golden Files

The library supports golden file testing without mocking:

import pytest
from pathlib import Path
from extrasheet import SheetsClient, LocalFileTransport

@pytest.fixture
def client():
    transport = LocalFileTransport(Path("tests/golden"))
    return SheetsClient(transport)

@pytest.mark.asyncio
async def test_pull(client, tmp_path):
    files = await client.pull("my_spreadsheet", tmp_path)
    assert (tmp_path / "my_spreadsheet" / "Sheet1" / "data.tsv").exists()

Golden files are stored as:

tests/golden/
  my_spreadsheet/
    metadata.json    # First API call response
    data.json        # Second API call response

Documentation

  • On-Disk Format - Complete specification of the file format
  • LLM Agent Guide - How to use extrasheet output for spreadsheet modifications
  • API Types - TypedDict definitions generated from Google Sheets API

Development

cd extrasheet
uv sync --all-extras
uv run pytest tests/ -v
uv run ruff check .
uv run ruff format .
uv run mypy src/extrasheet

License

MIT License - see LICENSE for details.

Part of ExtraSuite

This package is part of the ExtraSuite project, which provides AI agents with secure access to Google Workspace files.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

extrasheet-0.2.1.tar.gz (201.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

extrasheet-0.2.1-py3-none-any.whl (109.0 kB view details)

Uploaded Python 3

File details

Details for the file extrasheet-0.2.1.tar.gz.

File metadata

  • Download URL: extrasheet-0.2.1.tar.gz
  • Upload date:
  • Size: 201.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for extrasheet-0.2.1.tar.gz
Algorithm Hash digest
SHA256 b1aeffb6cca4b7e00da9e260bb4c475e800ddde226d96b38369317ba3d934180
MD5 2764bd8f6bdf432ef1720fe60ac6b3bb
BLAKE2b-256 0e35932c1b209d78003a96431be370742b939fcce6224c577bed532d70e90fa9

See more details on using hashes here.

Provenance

The following attestation bundles were made for extrasheet-0.2.1.tar.gz:

Publisher: publish-extrasheet.yml on think41/extrasuite

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file extrasheet-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: extrasheet-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 109.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for extrasheet-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ddbacb9447c064823a18bd6f53cd7e0883626058b3f9684c4276b7f9b5f0807b
MD5 17ab00faaf4f66ff5221444ebf4aa513
BLAKE2b-256 9fdf3969cd7e5866f340955ef5e8085b04563a9d4eabb1cb458c7348277173c5

See more details on using hashes here.

Provenance

The following attestation bundles were made for extrasheet-0.2.1-py3-none-any.whl:

Publisher: publish-extrasheet.yml on think41/extrasuite

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page