sections
9 rows where breadcrumbs = "["Plugin hooks"]" and references = "[]"
This data as json, CSV (advanced)
Suggested facets: breadcrumbs (array)
| id ▼ | page | ref | title | content | breadcrumbs | references |
|---|---|---|---|---|---|---|
| plugin_hooks:plugin-actions | plugin_hooks | plugin-actions | Action hooks | Action hooks can be used to add items to the action menus that appear at the top of different pages within Datasette. Unlike menu_links() , actions which are displayed on every page, actions should only be relevant to the page the user is currently viewing. Each of these hooks should return return a list of {"href": "...", "label": "..."} menu items, with optional "description": "..." keys describing each action in more detail. They can alternatively return an async def awaitable function which, when called, returns a list of those menu items. | ["Plugin hooks"] | [] |
| plugin_hooks:plugin-event-tracking | plugin_hooks | plugin-event-tracking | Event tracking | Datasette includes an internal mechanism for tracking notable events. This can be used for analytics, but can also be used by plugins that want to listen out for when key events occur (such as a table being created) and take action in response. Plugins can register to receive events using the track_event plugin hook. They can also define their own events for other plugins to receive using the register_events() plugin hook , combined with calls to the datasette.track_event() internal method . | ["Plugin hooks"] | [] |
| plugin_hooks:plugin-hook-forbidden | plugin_hooks | plugin-hook-forbidden | forbidden(datasette, request, message) | datasette - Datasette class You can use this to access plugin configuration options via datasette.plugin_config(your_plugin_name) , or to render templates or execute SQL queries. request - Request object The current HTTP request. message - string A message hinting at why the request was forbidden. Plugins can use this to customize how Datasette responds when a 403 Forbidden error occurs - usually because a page failed a permission check, see Permissions . If a plugin hook wishes to react to the error, it should return a Response object . This example returns a redirect to a /-/login page: from datasette import hookimpl from urllib.parse import urlencode @hookimpl def forbidden(request, message): return Response.redirect( "/-/login?=" + urlencode({"message": message}) ) The function can alternatively return an awaitable function if it needs to make any asynchronous method calls. This example renders a template: from datasette import hookimpl, Response @hookimpl def forbidden(datasette): async def inner(): return Response.html( await datasette.render_template( "render_message.html", request=request ) ) return inner | ["Plugin hooks"] | [] |
| plugin_hooks:plugin-hook-permission-resources-sql | plugin_hooks | plugin-hook-permission-resources-sql | permission_resources_sql(datasette, actor, action) | datasette - Datasette class Access to the Datasette instance. actor - dictionary or None The current actor dictionary. None for anonymous requests. action - string The permission action being evaluated. Examples include "view-table" or "insert-row" . Return value A datasette.permissions.PermissionSQL object, None or an iterable of PermissionSQL objects. Datasette's action-based permission resolver calls this hook to gather SQL rows describing which resources an actor may access ( allow = 1 ) or should be denied ( allow = 0 ) for a specific action. Each SQL snippet should return parent , child , allow and reason columns. Parameter naming convention: Plugin parameters in PermissionSQL.params should use unique names to avoid conflicts with other plugins. The recommended convention is to prefix parameters with your plugin's source name (e.g., myplugin_user_id ). The system reserves these parameter names: :actor , :actor_id , :action , and :filter_parent . You can also use return PermissionSQL.allow(reason="reason goes here") or PermissionSQL.deny(reason="reason goes here") as shortcuts for simple root-level allow or deny rules. These will create SQL snippets that look like this: SELECT NULL AS parent, NULL AS child, 1 AS allow, 'reason goes here' AS reason Or 0 AS allow for denies. | ["Plugin hooks"] | [] |
| plugin_hooks:plugin-hook-register-magic-parameters | plugin_hooks | plugin-hook-register-magic-parameters | register_magic_parameters(datasette) | datasette - Datasette class You can use this to access plugin configuration options via datasette.plugin_config(your_plugin_name) . Magic parameters can be used to add automatic parameters to canned queries . This plugin hook allows additional magic parameters to be defined by plugins. Magic parameters all take this format: _prefix_rest_of_parameter . The prefix indicates which magic parameter function should be called - the rest of the parameter is passed as an argument to that function. To register a new function, return it as a tuple of (string prefix, function) from this hook. The function you register should take two arguments: key and request , where key is the rest_of_parameter portion of the parameter and request is the current Request object . This example registers two new magic parameters: :_request_http_version returning the HTTP version of the current request, and :_uuid_new which returns a new UUID. It also registers an :_asynclookup_key parameter, demonstrating that these functions can be asynchronous: from datasette import hookimpl from uuid import uuid4 def uuid(key, request): if key == "new": return str(uuid4()) else: raise KeyError def request(key, request): if key == "http_version": return request.scope["http_version"] else: raise KeyError async def asynclookup(key, request): return await do_something_async(key) @hookimpl def register_magic_parameters(datasette): return [ ("request", request), ("uuid", uuid), ("asynclookup", asynclookup), ] | ["Plugin hooks"] | [] |
| plugin_hooks:plugin-hook-write-wrapper | plugin_hooks | plugin-hook-write-wrapper | write_wrapper(datasette, database, request, transaction) | datasette - Datasette class You can use this to access plugin configuration options via datasette.plugin_config(your_plugin_name) . database - string The name of the database being written to. request - Request object or None The HTTP request that triggered this write, if available. This will be None for writes that do not originate from an HTTP request (e.g. writes triggered by plugins during startup). transaction - bool True if the write will be wrapped in a database transaction. Return a generator function that accepts a conn argument (a SQLite connection object) and optionally a track_event argument. The generator should yield exactly once. Code before the yield runs before the write function executes; code after the yield runs after it completes. The result of the write function is sent back through the yield , so you can capture it with result = yield . If the write function raises an exception, it is thrown into the generator so you can handle it with a try / except around the yield . If your generator accepts track_event , you can call track_event(event) to queue an event that will be dispatched via datasette.track_event() after the write commits successfully. Events are discarded if the write raises an exception. Return None to skip wrapping for this particular write. This example logs every write operation: from datasette import hookimpl @hookimpl def write_wrapper(datasette, database, req… | ["Plugin hooks"] | [] |
| plugin_hooks:plugin-page-extras | plugin_hooks | plugin-page-extras | Page extras | These plugin hooks can be used to affect the way HTML pages for different Datasette interfaces are rendered. | ["Plugin hooks"] | [] |
| plugin_hooks:plugin-register-actions | plugin_hooks | plugin-register-actions | register_actions(datasette) | If your plugin needs to register actions that can be checked with Datasette's new resource-based permission system, return a list of those actions from this hook. Actions define what operations can be performed on resources (like viewing a table, executing SQL, or custom plugin actions). from datasette import hookimpl from datasette.permissions import Action, Resource class DocumentCollectionResource(Resource): """A collection of documents.""" name = "document-collection" parent_class = None def __init__(self, collection: str): super().__init__(parent=collection, child=None) @classmethod async def resources_sql( cls, datasette, actor=None ) -> str: return """ SELECT collection_name AS parent, NULL AS child FROM document_collections """ class DocumentResource(Resource): """A document in a collection.""" name = "document" parent_class = DocumentCollectionResource def __init__(self, collection: str, document: str): super().__init__(parent=collection, child=document) @classmethod async def resources_sql( cls, datasette, actor=None ) -> str: return """ SELECT collection_name AS parent, document_id AS child FROM documents """ @hookimpl def register_actions(datasette): return [ Action( name="list-documents", abbr="ld", description="List documents in a collection", resource_class=DocumentCollectionResource, ), Action( name="view-document", abbr="vdoc", description="View document", resource_class=DocumentResource, ), Action( name="edit-document", abbr="edoc", description="Edit document", resource_class=DocumentResource, ), ] The fields of the Action dataclass are as follows: … | ["Plugin hooks"] | [] |
| plugin_hooks:plugin-register-column-types | plugin_hooks | plugin-register-column-types | register_column_types(datasette) | Return a list of ColumnType subclasses (not instances) to register custom column types. Column types define how values in specific columns are rendered, validated, and transformed. from datasette import hookimpl from datasette.column_types import ColumnType, SQLiteType import markupsafe class ColorColumnType(ColumnType): name = "color" description = "CSS color value" sqlite_types = (SQLiteType.TEXT,) async def render_cell( self, value, column, table, database, datasette, request, ): if value: return markupsafe.Markup( '<span style="background-color: {color}">' "{color}</span>" ).format(color=markupsafe.escape(value)) return None async def validate(self, value, datasette): if value and not value.startswith("#"): return "Color must start with #" return None async def transform_value(self, value, datasette): # Normalize to uppercase if isinstance(value, str): return value.upper() return value @hookimpl def register_column_types(datasette): return [ColorColumnType] Each ColumnType subclass must define the following class attributes: name - string Unique identifier for the column type, e.g. "color" . Must be unique across all plugins. description - string Human-readable label, e.g. "CSS color value" . sqlite_types - tuple of SQLiteType values, optional Restrict assignments of this column type to columns with matching SQLite types, e.g. (SQLiteType.TEXT,) . If omitted, the column type can be assigned… | ["Plugin hooks"] | [] |
Advanced export
JSON shape: default, array, newline-delimited, object
CREATE TABLE [sections] ( [id] TEXT PRIMARY KEY, [page] TEXT, [ref] TEXT, [title] TEXT, [content] TEXT, [breadcrumbs] TEXT, [references] TEXT );