id,page,ref,title,content,breadcrumbs,references plugin_hooks:plugin-hook-register-events,plugin_hooks,plugin-hook-register-events,register_events(datasette),"datasette - Datasette class You can use this to access plugin configuration options via datasette.plugin_config(your_plugin_name) . This hook should return a list of Event subclasses that represent custom events that the plugin might send to the datasette.track_event() method. This example registers event subclasses for ban-user and unban-user events: from dataclasses import dataclass from datasette import hookimpl, Event @dataclass class BanUserEvent(Event): name = ""ban-user"" user: dict @dataclass class UnbanUserEvent(Event): name = ""unban-user"" user: dict @hookimpl def register_events(): return [BanUserEvent, UnbanUserEvent] The plugin can then call datasette.track_event(...) to send a ban-user event: await datasette.track_event( BanUserEvent(user={""id"": 1, ""username"": ""cleverbot""}) )","[""Plugin hooks"", ""Event tracking""]",[] plugin_hooks:plugin-hook-track-event,plugin_hooks,plugin-hook-track-event,"track_event(datasette, event)","datasette - Datasette class You can use this to access plugin configuration options via datasette.plugin_config(your_plugin_name) . event - Event Information about the event, represented as an instance of a subclass of the Event base class. This hook will be called any time an event is tracked by code that calls the datasette.track_event(...) internal method. The event object will always have the following properties: name : a string representing the name of the event, for example logout or create-table . actor : a dictionary representing the actor that triggered the event, or None if the event was not triggered by an actor. created : a datatime.datetime object in the timezone.utc timezone representing the time the event object was created. Other properties on the event will be available depending on the type of event. You can also access those as a dictionary using event.properties() . The events fired by Datasette core are documented here . This example plugin logs details of all events to standard error: from datasette import hookimpl import json import sys @hookimpl def track_event(event): name = event.name actor = event.actor properties = event.properties() msg = json.dumps( { ""name"": name, ""actor"": actor, ""properties"": properties, } ) print(msg, file=sys.stderr, flush=True) The function can also return an async function which will be awaited. This is useful for writing to a database. This example logs events to a datasette_events table in a database called events . It uses the startup() hook to create that table if it does not exist. from datasette import hookimpl import json @hookimpl def startup(datasette): async def inner(): db = datasette.get_database(""events"") await db.execute_write( """""" create table if not exists datasette_events ( id integer primary key, event_type text, created text, actor text, properties text ) """""" ) return inner @hookimpl def track_event(datasette, event): async def inner(): db = datasette.get_database(""events"") properties = event.properties() await db.execute_write( """""" insert into datasette_events (event_type, created, actor, properties) values (?, strftime('%Y-%m-%d %H:%M:%S', 'now'), ?, ?) """""", (event.name, json.dumps(event.actor), json.dumps(properties)), ) return inner Example: datasette-events-db","[""Plugin hooks"", ""Event tracking""]","[{""href"": ""https://datasette.io/plugins/datasette-events-db"", ""label"": ""datasette-events-db""}]"