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

Uploaded Python 3

File details

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

File metadata

  • Download URL: shillelagh_gristapi-0.1.6.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.6.tar.gz
Algorithm Hash digest
SHA256 2454053e6987b19d9b892943f1226049eed73e115c1927f8cbeb860c0e08973f
MD5 e94e31f7b38c8689aabf3135c29f13e8
BLAKE2b-256 8382d5cbb19127909f51796f8ffed35fab3fc11ee12eecb8514c9541432bad6e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for shillelagh_gristapi-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 6e9905797786400cb455cc603e83763c69cc3efd35ba0ad468d0f2d10fbf9e29
MD5 1f0eb3d17f012a84d4ea956ac3042fca
BLAKE2b-256 83e9d51fac7b4c081864489fba90d529951994bf85e98f579d5efc4429d3f7ba

See more details on using hashes here.

Provenance

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