Contributers guide

The WidgetServer class is used for serving Python functions as widgets or API endpoints.

class dashboard.server.WidgetServer(widget_path, resolver=None, settings=None)[source]

Python framework for serving little widgets.

Widgets can be stored in dashboard/widgets/.

Any function ending with _widget will be routed to /api/widgets/widget_name. For example, time_widget is routed to /api/widgets/time.

Widgets are loaded from widget_path.

An example widget looks like:

import datetime

async def time_widget(request):
    return {
        "date": datetime.datetime.now().strftime("%A %B %d, %Y"),
    }

The widget can then be served as a JSON response or via HTML.

If HTML is requested, the returned JSON will be passed to the Jinja template ($widget_path/templates/$widget_name.jinja.html) and rendered:

<div>{{ date }}</div>

Static assets are served from /static.

get_template(name, ssml=False)[source]

Fetch a template so it can be used for rendering.

index(request)[source]

Render the index page.

load()[source]

Load all widgets.

skill_endpoint(request)[source]

Widgets can be exposed as Alexa skills by creating a SSML file indicating how to render the response.

The SSML file should be in the templates file as widget_name.jinja.ssml.

start()[source]

Start the widget server.

stop()[source]

Stop the widget server.

widget(name, func)[source]

Add a widget function.