Skip to main content

Shillelagh adapter to query Grist documents and tables via SQL.

Project description

shillelagh-gristapi

Shillelagh adapter for querying Grist Documents.

Command line usage

Configuration in ~/.config/shillelagh/shillelagh.yaml:

gristapi:
  api_key: <replace-with-your-key>
  server: <replace-with-your-server>
  org_id: <replace-with-your-org-id>
  expire_after: <replace-with-cache-timeout-in-seconds>
  cache_name: <replace-with-cache-name-in-filesystem>
  • find your api_key in your profile settings,
  • set server to your server url, e.g. https://templates.getgrist.com,
  • find your org_id with the orgs endpoint, e.g. curl -H "Authorization: Bearer <replace-with-your-apy-key> "<replace-with-your-server>/api/orgs/" | jq '.[]|.id',
  • default cache timeout is 0,
  • default cache name is grist_cache.
$ 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 usage

import os

from shillelagh.backends.apsw.db import connect

connection = connect(
    ":memory:",
    adapter_kwargs={
        "gristapi": {
            "api_key": os.environ["GRIST_API_KEY"],
            "server": os.environ["GRIST_SERVER"],
            "org_id": os.environ["GRIST_ORG_ID"],
            "expire_after": os.environ["CACHE_SEC"],
            "cache_name": os.environ["CACHE_NAME"],
        }
    },
)
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()

Superset usage

To make the shillelagh-gristapi plugin available, add the following to your requirements-local.txt file:

shillelagh
shillelagh-gristapi

SqlAlchemy URI

shillelagh+safe://

Engine parameters

{
  "connect_args":
    {
      "adapters":
        ["gristapi"],
      "adapter_kwargs":
        {
          "gristapi":{
            "api_key": "<REPLACE_WITH_YOUR_API_KEY>",
            "server": "<REPLACE_WITH_YOUR_SERVER_URL>",
            "org_id": "<REPLACE_WITH_YOUR_ORD_ID>",
            "expire_after": 3600,
            "cache_name": "grist_name"
          }
        }
    }
}
SqlAlchemy URI Engine parameters
screenshot base screenshot parametres
SQL Lab
screenshot sql lab

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: shillelagh_gristapi-0.1.0.tar.gz
  • Upload date:
  • Size: 16.2 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.0.tar.gz
Algorithm Hash digest
SHA256 ff0ed5b4dbcc71ce8f482966e94c42f88e3a79b966c715e3fe01d465b5e68a55
MD5 01b8e1a55650d9bba7ee98ee21e0573b
BLAKE2b-256 16a5733b5c6287dc030f7efaccfdf6624b55aacbb71b3cd47a98a2eb66171a60

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for shillelagh_gristapi-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9570147a5e5e8fa3e0e5d0b6db400b781da81ab71b8ea19a905c142e534627b0
MD5 8bf4f416bb1fa3b3ca78a6fd33083b5f
BLAKE2b-256 dab7b2cc43b16768feb47de4e2085c4addc22a0a0bc0edecd9c437fb5b1ec0a0

See more details on using hashes here.

Provenance

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