Skip to main content

Share anywidgets via GitHub Gists

Project description

gistwidget

Labs — This is an experimental project. And not recommended for production use.

Share anywidgets via GitHub Gists. Two functions, zero config.

Build a widget in a notebook, publish it to a gist, and anyone can load it back — JS, CSS, Python traitlets and all.

Install

uv add gistwidget
# or
pip install gistwidget

Quickstart

Load a widget someone already published:

import gistwidget

Widget = gistwidget.load("4de49e3627f06804c53d235f004d41c0")
Widget()

Publish your own:

import os
import anywidget
import traitlets
import gistwidget

class CounterWidget(anywidget.AnyWidget):
    _esm = """
    export default {
      render({ model, el }) {
        let btn = document.createElement("button");
        btn.innerText = `Count: ${model.get("count")}`;
        btn.addEventListener("click", () => {
          model.set("count", model.get("count") + 1);
          model.save_changes();
        });
        model.on("change:count", () => {
          btn.innerText = `Count: ${model.get("count")}`;
        });
        el.appendChild(btn);
      }
    };
    """
    count = traitlets.Int(0).tag(sync=True)

result = gistwidget.publish(
    CounterWidget,
    description="Counter widget",
    token=os.getenv("GITHUB_TOKEN"),
)
print(result.html_url)

API

gistwidget.load(gist_id, *, token=None)

Load a widget class from a GitHub Gist.

Parameter Type Description
gist_id str Gist ID, user/id, or full URL
token str | None GitHub token (only needed for private gists)

Returns a type[anywidget.AnyWidget] — the widget class, not an instance. Call it to create one.

gistwidget.publish(widget, *, gist_id=None, description="", public=False, token=None)

Publish a widget to a GitHub Gist.

Parameter Type Description
widget type | instance An AnyWidget class or instance
gist_id str | None Update an existing gist (omit to create new)
description str Gist description
public bool Public or secret gist
token str GitHub token (required)

Returns a GistResult with .gist_id and .html_url.

GistResult

@dataclass
class GistResult:
    gist_id: str
    html_url: str

GistError

Raised on API errors or invalid input. Has an optional .status_code attribute for HTTP errors.

What gets stored in the gist

File Contents When
widget.js Your _esm JavaScript Always
widget.css Your _css stylesheet If _css is set
widget.py Traitlet definitions If the widget has custom traitlets

When loading, all three are reassembled into a working widget class.

Notebooks

The notebooks/ directory contains marimo notebooks:

  • load_widget.py — Interactive loader: paste a gist ID, get a live widget
  • publish_widget.py — Defines a drawing-canvas widget and publishes it

Development

uv pip install -e ".[dev]"
pytest tests/

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

gistwidget-0.1.2.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

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

gistwidget-0.1.2-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file gistwidget-0.1.2.tar.gz.

File metadata

  • Download URL: gistwidget-0.1.2.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.8 {"installer":{"name":"uv","version":"0.10.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for gistwidget-0.1.2.tar.gz
Algorithm Hash digest
SHA256 21a7cc6a6b476d6828204804567adfd2abb44603bf4ce31abf5df24448df3308
MD5 3511f1c93a8d0a3e02c943a3b24bd455
BLAKE2b-256 fa7e0a2e4ff7f471b89e7a845e39f9241327b91bf526d9ebfb3b08f8bcff285d

See more details on using hashes here.

File details

Details for the file gistwidget-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: gistwidget-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.8 {"installer":{"name":"uv","version":"0.10.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for gistwidget-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6cc9f670e1b9ca558ba9f8dec4a206c0b4c0ff0cec3195a4e4f04e079e3b9d30
MD5 ef2c1314c767e54fcb750391abac5d7e
BLAKE2b-256 5fbcbe58955e17f70095abb7d3851852c3ea4f6aa19c90fc2539ff5c3c8025d4

See more details on using hashes here.

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