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.7.tar.gz (18.5 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.7-py3-none-any.whl (18.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: shillelagh_gristapi-0.1.7.tar.gz
  • Upload date:
  • Size: 18.5 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.7.tar.gz
Algorithm Hash digest
SHA256 ea2eb501cf3faa19cf94f84a37792d169b3050120c881a67c78cd9c499af7b70
MD5 3467a6b6819d4902466fe66b42c96432
BLAKE2b-256 f91d0d4c879c250065fdbacd5bbc9a5f5ae576a3b8a94ee4856886b588726288

See more details on using hashes here.

Provenance

The following attestation bundles were made for shillelagh_gristapi-0.1.7.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.7-py3-none-any.whl.

File metadata

File hashes

Hashes for shillelagh_gristapi-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 76a05d7968a709ea1ae9e1cb236f7c2b9d4e4e953511900782e25655314253a0
MD5 0153f62bee4ddb47f459bd2ae1b20fae
BLAKE2b-256 6745ae05ac04e74664196a06a7430a3fc85d0eb77a89384e202e0793884660d4

See more details on using hashes here.

Provenance

The following attestation bundles were made for shillelagh_gristapi-0.1.7-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