diff --git a/docs/demo/demo-notebook.ipynb b/docs/demo/demo-notebook.ipynb index cc2a872..8c58526 100644 --- a/docs/demo/demo-notebook.ipynb +++ b/docs/demo/demo-notebook.ipynb @@ -1,255 +1,169 @@ { - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Install Jupyter Events from piplite." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from __future__ import annotations\n", - "\n", - "import piplite\n", - "\n", - "await piplite.install(\"jupyter_events\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The `EventLogger` is the main object in Jupyter Events." - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [], - "source": [ - "from jupyter_events.logger import EventLogger\n", - "\n", - "logger = EventLogger()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "To begin emitting events from a Python application, you need to tell the `EventLogger` what events you'd like to emit. To do this, we should register our event's schema (more on this later) with the logger." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{\n", - " \"$id\": \"http://myapplication.org/example-event\",\n", - " \"version\": 1,\n", - " \"title\": \"Example Event\",\n", - " \"description\": \"An interesting event to collect\",\n", - " \"properties\": {\n", - " \"name\": {\n", - " \"title\": \"Name of Event\",\n", - " \"type\": \"string\"\n", - " }\n", - " }\n", - "}\n" - ] + "metadata": { + "kernelspec": { + "name": "python", + "display_name": "Python (Pyodide)", + "language": "python" + }, + "language_info": { + "codemirror_mode": { + "name": "python", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8" + }, + "vscode": { + "interpreter": { + "hash": "fa70b7d208e0e2ef401b5613e3a2c366a3ff98da2f39442a36f3be51bccaa21d" + } } - ], - "source": [ - "schema = \"\"\"\n", - "$id: http://myapplication.org/example-event\n", - "version: \"1\"\n", - "title: Example Event\n", - "description: An interesting event to collect\n", - "properties:\n", - " name:\n", - " title: Name of Event\n", - " type: string\n", - "\"\"\"\n", - "\n", - "\n", - "logger.register_event_schema(schema)\n", - "print(logger.schemas)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\n", - "Now that the logger knows about the event, it needs to know _where_ to send it. To do this, we register a logging _Handler_ —borrowed from Python's standard [`logging`](https://docs.python.org/3/library/logging.html) library—to route the events to the proper place." - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [], - "source": [ - "# We will import one of the handlers from Python's logging library\n", - "from logging import StreamHandler\n", - "\n", - "handler = StreamHandler()\n", - "\n", - "logger.register_handler(handler)" - ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The logger knows about the event and where to send it; all that's left is to emit an instance of the event!" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [ + "nbformat_minor": 4, + "nbformat": 4, + "cells": [ { - "name": "stderr", - "output_type": "stream", - "text": [ - "{\"__timestamp__\": \"2024-05-04T23:22:40.338884+00:00Z\", \"__schema__\": \"http://myapplication.org/example-event\", \"__schema_version__\": 1, \"__metadata_version__\": 1, \"name\": \"My Event\"}\n" - ] + "cell_type": "code", + "source": "from __future__ import annotations\n\n%pip install jupyter_events", + "metadata": { + "trusted": true + }, + "outputs": [], + "execution_count": 1 }, { - "data": { - "text/plain": [ - "{'__timestamp__': '2024-05-04T23:22:40.338884+00:00Z',\n", - " '__schema__': 'http://myapplication.org/example-event',\n", - " '__schema_version__': 1,\n", - " '__metadata_version__': 1,\n", - " 'name': 'My Event'}" - ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "logger.emit(schema_id=\"http://myapplication.org/example-event\", data={\"name\": \"My Event\"})" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Now, let's demo adding a listener to the already registered event." - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [], - "source": [ - "async def my_listener(logger: EventLogger, schema_id: str, data: dict) -> None:\n", - " print(\"hello, from my_listener\")\n", - " print(logger)\n", - " print(schema_id)\n", - " print(data)\n", - "\n", - "\n", - "logger.add_listener(schema_id=\"http://myapplication.org/example-event\", listener=my_listener)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "If we emit the event again, you'll see our listener \"sees\" the event and executes some code:" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [ + "cell_type": "markdown", + "source": "The `EventLogger` is the main object in Jupyter Events.", + "metadata": {} + }, + { + "cell_type": "code", + "source": "from jupyter_events.logger import EventLogger\n\nlogger = EventLogger()", + "metadata": { + "trusted": true + }, + "outputs": [], + "execution_count": 2 + }, { - "name": "stderr", - "output_type": "stream", - "text": [ - "{\"__timestamp__\": \"2024-05-04T23:22:40.400243+00:00Z\", \"__schema__\": \"http://myapplication.org/example-event\", \"__schema_version__\": 1, \"__metadata_version__\": 1, \"name\": \"My Event\"}\n" - ] + "cell_type": "markdown", + "source": "To begin emitting events from a Python application, you need to tell the `EventLogger` what events you'd like to emit. To do this, we should register our event's schema (more on this later) with the logger.", + "metadata": {} }, { - "data": { - "text/plain": [ - "{'__timestamp__': '2024-05-04T23:22:40.400243+00:00Z',\n", - " '__schema__': 'http://myapplication.org/example-event',\n", - " '__schema_version__': 1,\n", - " '__metadata_version__': 1,\n", - " 'name': 'My Event'}" - ] - }, - "execution_count": 7, - "metadata": {}, - "output_type": "execute_result" + "cell_type": "code", + "source": "schema = \"\"\"\n$id: http://myapplication.org/example-event\nversion: \"1\"\ntitle: Example Event\ndescription: An interesting event to collect\nproperties:\n name:\n title: Name of Event\n type: string\n\"\"\"\n\n\nlogger.register_event_schema(schema)\nprint(logger.schemas)", + "metadata": { + "trusted": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": "{\n \"$id\": \"http://myapplication.org/example-event\",\n \"version\": \"1\",\n \"title\": \"Example Event\",\n \"description\": \"An interesting event to collect\",\n \"properties\": {\n \"name\": {\n \"title\": \"Name of Event\",\n \"type\": \"string\"\n }\n }\n}\n" + } + ], + "execution_count": 3 }, { - "name": "stdout", - "output_type": "stream", - "text": [ - "hello, from my_listener\n", - "\n", - "http://myapplication.org/example-event\n", - "{'name': 'My Event'}\n" - ] + "cell_type": "markdown", + "source": "\nNow that the logger knows about the event, it needs to know _where_ to send it. To do this, we register a logging _Handler_ —borrowed from Python's standard [`logging`](https://docs.python.org/3/library/logging.html) library—to route the events to the proper place.", + "metadata": {} + }, + { + "cell_type": "code", + "source": "# We will import one of the handlers from Python's logging library\nfrom logging import StreamHandler\n\nhandler = StreamHandler()\n\nlogger.register_handler(handler)", + "metadata": { + "trusted": true + }, + "outputs": [], + "execution_count": 4 + }, + { + "cell_type": "markdown", + "source": "The logger knows about the event and where to send it; all that's left is to emit an instance of the event!", + "metadata": {} + }, + { + "cell_type": "code", + "source": "logger.emit(schema_id=\"http://myapplication.org/example-event\", data={\"name\": \"My Event\"})", + "metadata": { + "trusted": true + }, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": "{\"__timestamp__\": \"2025-09-05T08:32:54.425000+00:00Z\", \"__schema__\": \"http://myapplication.org/example-event\", \"__schema_version__\": \"1\", \"__metadata_version__\": 1, \"name\": \"My Event\"}\n" + }, + { + "execution_count": 5, + "output_type": "execute_result", + "data": { + "text/plain": "{'__timestamp__': '2025-09-05T08:32:54.425000+00:00Z',\n '__schema__': 'http://myapplication.org/example-event',\n '__schema_version__': '1',\n '__metadata_version__': 1,\n 'name': 'My Event'}" + }, + "metadata": {} + } + ], + "execution_count": 5 + }, + { + "cell_type": "markdown", + "source": "Now, let's demo adding a listener to the already registered event.", + "metadata": {} + }, + { + "cell_type": "code", + "source": "async def my_listener(logger: EventLogger, schema_id: str, data: dict) -> None:\n print(\"hello, from my_listener\")\n print(logger)\n print(schema_id)\n print(data)\n\n\nlogger.add_listener(schema_id=\"http://myapplication.org/example-event\", listener=my_listener)", + "metadata": { + "trusted": true + }, + "outputs": [], + "execution_count": 6 + }, + { + "cell_type": "markdown", + "source": "If we emit the event again, you'll see our listener \"sees\" the event and executes some code:", + "metadata": {} + }, + { + "cell_type": "code", + "source": "logger.emit(schema_id=\"http://myapplication.org/example-event\", data={\"name\": \"My Event\"})", + "metadata": { + "trusted": true + }, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": "{\"__timestamp__\": \"2025-09-05T08:33:02.006000+00:00Z\", \"__schema__\": \"http://myapplication.org/example-event\", \"__schema_version__\": \"1\", \"__metadata_version__\": 1, \"name\": \"My Event\"}\n" + }, + { + "execution_count": 7, + "output_type": "execute_result", + "data": { + "text/plain": "{'__timestamp__': '2025-09-05T08:33:02.006000+00:00Z',\n '__schema__': 'http://myapplication.org/example-event',\n '__schema_version__': '1',\n '__metadata_version__': 1,\n 'name': 'My Event'}" + }, + "metadata": {} + }, + { + "name": "stdout", + "output_type": "stream", + "text": "hello, from my_listener\n\nhttp://myapplication.org/example-event\n{'name': 'My Event'}\n" + } + ], + "execution_count": 7 + }, + { + "cell_type": "code", + "source": "", + "metadata": {}, + "outputs": [], + "execution_count": null } - ], - "source": [ - "logger.emit(schema_id=\"http://myapplication.org/example-event\", data={\"name\": \"My Event\"})" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3.8.10 ('jupyter_events')", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.8.10" - }, - "orig_nbformat": 4, - "vscode": { - "interpreter": { - "hash": "fa70b7d208e0e2ef401b5613e3a2c366a3ff98da2f39442a36f3be51bccaa21d" - } - } - }, - "nbformat": 4, - "nbformat_minor": 2 + ] } diff --git a/docs/demo/index.md b/docs/demo/index.md index be3c23f..86a947c 100644 --- a/docs/demo/index.md +++ b/docs/demo/index.md @@ -2,7 +2,7 @@ Try out the Jupyter Events Library in the example notebook below (powered by JupyterLite): -```{retrolite} demo-notebook.ipynb +```{notebooklite} demo-notebook.ipynb --- width: 100% height: 1200px diff --git a/pyproject.toml b/pyproject.toml index 16c20df..6f1c5b5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -54,7 +54,7 @@ jupyter-events = "jupyter_events.cli:main" [project.optional-dependencies] docs = [ "sphinx>=8", - "jupyterlite-sphinx", + "jupyterlite-sphinx>=0.21.0,<0.22", "myst_parser", "pydata_sphinx_theme>=0.16", "sphinxcontrib-spelling",