> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mindsdb.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Google Sheets

This is the implementation of the Google Sheets data handler for MindsDB.

[Google Sheets](https://www.google.com/sheets/about/) is a spreadsheet program included as a part of the free, web-based Google Docs Editors suite offered by Google.

<Warning>
  Please note that the integration of MindsDB with Google Sheets works for public sheets only.
</Warning>

## Prerequisites

Before proceeding, ensure the following prerequisites are met:

1. Install MindsDB locally via [Docker](/setup/self-hosted/docker) or [Docker Desktop](/setup/self-hosted/docker-desktop).
2. To connect Google Sheets to MindsDB, install the required dependencies following [this instruction](/setup/self-hosted/docker#install-dependencies).
3. Install or ensure access to Google Sheets.

## Implementation

This handler is implemented using `duckdb`, a library that allows SQL queries to be executed on `pandas` DataFrames.

In essence, when querying a particular sheet, the entire sheet is first pulled into a `pandas` DataFrame using the [Google Visualization API](https://developers.google.com/chart/interactive/docs/reference). Once this is done, SQL queries can be run on the DataFrame using `duckdb`.

<Tip>
  Since the entire sheet needs to be pulled into memory first (DataFrame), it is recommended to be somewhat careful when querying large datasets so as not to overload your machine.
</Tip>

The required arguments to establish a connection are as follows:

* `spreadsheet_id` is the unique ID of the Google Sheet.
* `sheet_name` is the name of the sheet within the Google Sheet.

## Usage

In order to make use of this handler and connect to a Google Sheet in MindsDB, the following syntax can be used:

```sql theme={null}
CREATE DATABASE sheets_datasource
WITH
    engine = 'sheets',
    parameters = {
      "spreadsheet_id": "12wgS-1KJ9ymUM-6VYzQ0nJYGitONxay7cMKLnEE2_d0",
      "sheet_name": "iris"
    };
```

You can use this established connection to query your table as follows:

```sql theme={null}
SELECT *
FROM sheets_datasource.example_tbl;
```

The name of the table will be the name of the relevant sheet, provided as an input to the `sheet_name` parameter.

<Warning>
  At the moment, only the `SELECT` statemet is allowed to be executed through `duckdb`. This, however, has no restriction on running machine learning algorithms against your data in Google Sheets using the `CREATE MODEL` statement.
</Warning>
