Skip to main content

Shillelagh adapter to query Grist documents and tables via SQL.

Project description

shillelagh-gristapi

A Shillelagh adapter for the Grist REST API.
It lets you query Grist documents and tables with SQL via SQLite/SQLAlchemy,
ideal for BI tools like Apache Superset.


✨ Features

  • Query Grist documents, tables, and records as if they were SQL tables
  • Supports core SQL operations:
    • SELECT statements on Grist tables
    • Filter pushdown for = condition
    • Server-side sorting and LIMIT
  • Built-in discovery helpers:
    • grist:// → list all documents
    • grist://<doc_id> → list tables in a document
    • grist://<doc_id>/<table_id> → query rows in a table
  • Flexible usage:
    • CLI: via the shillelagh shell or python -m shillelagh_gristapi ...
    • Python: connect directly with the connect() API
    • Superset: drop-in integration for dashboards
  • Enforces Grist access rules:
    Your Grist permissions carry over automatically.
    If you can only see certain tables, columns, or rows in Grist,
    you’ll see exactly the same restrictions through this adapter.

🚀 Installation

pip install shillelagh-gristapi
# CLI
pip install 'shillelagh[console]'

Or from source:

git clone https://github.com/qleroy/shillelagh-gristapi.git
cd shillelagh-gristapi
pip install -e .[dev]

⚙️ Configuration

You need a Grist API key.

  • Fin doou API_KEY in your profile settings. See Grist docs.
  • Find your ORG_ID with the orgs endpoint, e.g. curl -H "Authorization: Bearer "/api/orgs/" | jq '.[]|.id',
gristapi:
  api_key: ${API_KEY} 
  org_id: ${ORG_ID} 
  server: ${SERVER} # e.g. https://docs.getgrist.com

🧑‍💻 Usage

🖥️ CLI

Default configuration in ~/.config/shillelagh/shillelagh.yaml:

$ shillelagh
# List document ids
# https://support.getgrist.com/api/#tag/workspaces/operation/listWorkspaces
SELECT * FROM 'grist://';

# List table ids
# https://support.getgrist.com/api/#tag/tables/operation/listTables
SELECT * FROM 'grist://<replace-with-a-doc-id>';

# Fetch records
# https://support.getgrist.com/api/#tag/records
SELECT * FROM 'grist://<replace-with-a-doc-id>/<replace-with-a-table-id>';

🐍 Python

import os

from shillelagh.backends.apsw.db import connect

connection = connect(
    ":memory:",
    adapter_kwargs={
        "gristapi": {
            "api_key": os.environ["GRIST_API_KEY"],
            "org_id": os.environ["GRIST_ORG_ID"],
            "server": os.environ["GRIST_SERVER"],
        }
    },
)
cursor = connection.cursor()

# List document ids
# https://support.getgrist.com/api/#tag/workspaces/operation/listWorkspaces
query_docs = "SELECT * FROM 'grist://';"
cursor.execute(query_docs).fetchall()

# List table ids
# https://support.getgrist.com/api/#tag/tables/operation/listTables
query_tables = "SELECT * FROM 'grist://<replace-with-a-doc-id>';"
cursor.execute(query_tables).fetchall()

# Fetch records
# https://support.getgrist.com/api/#tag/records
query = "SELECT * FROM 'grist://<replace-with-a-doc-id>/<replace-with-a-table-id>';"
cursor.execute(query).fetchall()

📊 Apache Superset

  • Install shillelagh + this adapter in your Superset image;
  • Add a Shillelagh database with URI
shillelagh+safe://
  • Configure the engine parameters
{
  "connect_args":
    {
      "adapters":
        ["gristapi"],
      "adapter_kwargs":
        {
          "gristapi":{
            "api_key": "<REPLACE_WITH_YOUR_API_KEY>",
            "org_id": "<REPLACE_WITH_YOUR_ORD_ID>",
            "server": "<REPLACE_WITH_YOUR_SERVER_URL>",
          }
        }
    }
}
  • Create a virtual dataset using a Grist URI, e.g.:
select * from 'grist://<doc-id>/<table-id>'
SqlAlchemy URI Engine parameters
screenshot base screenshot parametres
SQL Lab
screenshot sql lab

📄 License

MIT — see (LICENSE)[/LICENSE].

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

shillelagh_gristapi-0.1.5.tar.gz (18.4 kB view details)

Uploaded Source

Built Distribution

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

shillelagh_gristapi-0.1.5-py3-none-any.whl (18.1 kB view details)

Uploaded Python 3

File details

Details for the file shillelagh_gristapi-0.1.5.tar.gz.

File metadata

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

File hashes

Hashes for shillelagh_gristapi-0.1.5.tar.gz
Algorithm Hash digest
SHA256 a6f915a43a0512d9d6559fb67d0a686d2d4259fd578b128ff90924b46275a417
MD5 9b885af342bab91d646aa162e0d45471
BLAKE2b-256 e1c0f722e0b36fd09b83658de97ea3494c85d74c977b9f6f67fd5c287d84ef6b

See more details on using hashes here.

Provenance

The following attestation bundles were made for shillelagh_gristapi-0.1.5.tar.gz:

Publisher: pypi.yml on qleroy/shillelagh-gristapi

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

File details

Details for the file shillelagh_gristapi-0.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for shillelagh_gristapi-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 284ed26eb6c3040fd753496e9ea3a6aedeb655e4b3da00f1acba860a96f838a6
MD5 dc918dba7cbe8f27475fccd400239df6
BLAKE2b-256 154a70cd0061d06dd16dc154229bcdc213be354d56671a740d8e614aeb6f20ed

See more details on using hashes here.

Provenance

The following attestation bundles were made for shillelagh_gristapi-0.1.5-py3-none-any.whl:

Publisher: pypi.yml on qleroy/shillelagh-gristapi

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