inside the control area for that field in the row insert/edit dialog. A plugin can alternatively manipulate field.root directly and return nothing.
focus(field) - function, optional
Called when Datasette wants to focus this field, for example when focusing the first editable field in the dialog. Use this to focus the most useful interactive element inside the custom UI.
destroy(field) - function, optional
Called when Datasette tears down the insert/edit form. Use this to remove event listeners, close nested pickers, revoke object URLs, clear timers, or release other resources.",154,
774,Context object,"makeColumnField(context) is called with a context object describing the field. The current context object has these keys:
mode - string
""insert"" or ""edit"" .
database - string or null
The database name.
table - string or null
The table name.
tableUrl - string or null
The path to the table page, including any configured base URL prefix .
column - string
The column name.
columnType - object or null
The configured Datasette column type for this column, if one exists. This is null if no column type has been configured.
If present, this object has exactly these keys:
type - string
The registered column type name , matching the name attribute of the Python ColumnType subclass.
config - object
Configuration for this specific column type assignment. This is {} if no configuration has been set.
sqliteType - string or null
The SQLite affinity for this column, if known. This is one of ""TEXT"" , ""INTEGER"" , ""REAL"" , ""BLOB"" , ""NUMERIC"" or null if Datasette could not determine the affinity.
notNull - boolean
True if the column is defined as NOT NULL .
isPk - boolean
True if this column is part of the table's primary key.
defaultExpression - string or null
The SQLite default expression for the column, if available. This is null if the column has no SQLite default. For example, a column defined with DEFAULT (datetime('now')) will have ""datetime('now')"" here. This is the expression from the table schema, not the actual value SQLite will insert.
form - HTMLFormElement or null
The row insert/edit form element.
dialog - HTMLDialogElement or null
The modal dialog element.",154,
773,makeColumnField(context),"This method, if present, can provide a custom form field for a column in Datasette's row insert and edit dialogs.
It is designed for plugins that register custom column types using the Python register_column_types() plugin hook. For example, a plugin that defines a file column type can use makeColumnField() to replace a plain text input with a file picker, and a plugin that defines a rich text column type can use it to enhance the field with an editor.
Datasette calls makeColumnField(context) on each registered JavaScript plugin when it renders an editable insert/edit field. Plugins should inspect the context object and only return a control object if they can handle that field. Otherwise, use a bare return; .
The first plugin to return a truthy control object is used for that field. Plugins are called in registration order. If a plugin raises an exception, Datasette logs the error to the browser console and continues to the next plugin.
The row dialog tracks the value that will be sent to the insert/update API. The context object describes the column and form environment; custom controls should read and write field values using the field helper object passed to render(field) .",154,
772,makeColumnActions(columnDetails),"This method, if present, will be called when Datasette is rendering the cog action menu icons that appear at the top of the table view. By default these include options like ""Sort ascending/descending"" and ""Facet by this"", but plugins can return additional actions to be included in this menu.
The method will be called with a columnDetails object with the following keys:
columnName - string
The name of the column
columnNotNull - boolean
True if the column is defined as NOT NULL
columnType - string
The SQLite data type of the column
isPk - boolean
True if the column is part of the primary key
It should return a JavaScript array of objects each with a label and onClick property:
label - string
The human-readable label for the action
onClick(evt) - function
A function that will be called when the action is clicked
The evt object passed to the onClick is the standard browser event object that triggered the click.
This example plugin adds two menu items - one to copy the column name to the clipboard and another that displays the column metadata in an alert() window:
document.addEventListener('datasette_init', function(ev) {
ev.detail.registerPlugin('column-name-plugin', {
version: 0.1,
makeColumnActions: (columnDetails) => {
return [
{
label: 'Copy column to clipboard',
onClick: async (evt) => {
await navigator.clipboard.writeText(columnDetails.columnName)
}
},
{
label: 'Alert column metadata',
onClick: () => alert(JSON.stringify(columnDetails, null, 2))
}
];
}
});
});",154,
771,makeAboveTablePanelConfigs(),"This method should return a JavaScript array of objects defining additional panels to be added to the top of the table page. Each object should have the following:
id - string
A unique string ID for the panel, for example map-panel
label - string
A human-readable label for the panel
render(node) - function
A function that will be called with a DOM node to render the panel into
This example shows how a plugin might define a single panel:
document.addEventListener('datasette_init', function(ev) {
ev.detail.registerPlugin('panel-plugin', {
version: 0.1,
makeAboveTablePanelConfigs: () => {
return [
{
id: 'first-panel',
label: 'First panel',
render: node => {
node.innerHTML = '
My custom panel This is a custom panel that I added using a JavaScript plugin
';
}
}
]
}
});
});
When a page with a table loads, all registered plugins that implement makeAboveTablePanelConfigs() will be called and panels they return will be added to the top of the table page.",154,
770,makeJumpSections(context),"This method should return a JavaScript array of objects defining additional sections to be added to the blank state of the / jump menu, before the user starts typing a search.
It should return an array of objects, each with the following:
id - string
A unique string ID for the section, for example agent-chat
render(node, context) - function
A function that will be called with a DOM node to render the section into
Datasette passes a context object to both makeJumpSections(context) and render(node, context) . It has the following keys:
navigationSearch
The
custom element instance.
container - only for render()
The .results-container element used by the jump menu.
input - only for render()
The .search-input element used by the jump menu.
This example shows how a plugin might add a button for starting a new chat:
document.addEventListener('datasette_init', function(ev) {
ev.detail.registerPlugin('agent-plugin', {
version: 0.1,
makeJumpSections: (context) => {
return [
{
id: 'agent-chat',
render: (node, context) => {
node.innerHTML = 'Start a new chat ';
node.querySelector('button').addEventListener('click', () => {
location.href = '/-/agent/new';
});
}
}
];
}
});
});",154,
769,JavaScript plugin objects,"JavaScript plugins are blocks of code that can be registered with Datasette using the registerPlugin() method on the datasetteManager object.
The implementation object passed to this method should include a version key defining the plugin version, and one or more of the following named functions providing the implementation of the plugin:",154,
768,datasetteManager,"The datasetteManager object
VERSION - string
The version of Datasette
plugins - Map()
A Map of currently loaded plugin names to plugin implementations
registerPlugin(name, implementation)
Call this to register a plugin, passing its name and implementation
makeColumnField(context)
Calls the makeColumnField() hook on registered plugins, returning the first custom insert/edit field control that matches the provided field context. This is used internally by Datasette's row insert and edit dialogs.
selectors - object
An object providing named aliases to useful CSS selectors, listed below",154,
767,The datasette_init event,"Datasette emits a custom event called datasette_init when the page is loaded. This event is dispatched on the document object, and includes a detail object with a reference to the datasetteManager object.
Your JavaScript code can listen out for this event using document.addEventListener() like this:
document.addEventListener(""datasette_init"", function (evt) {
const manager = evt.detail;
console.log(""Datasette version:"", manager.VERSION);
});",154,
766,JavaScript plugins,"Datasette can run custom JavaScript in several different ways:
Datasette plugins written in Python can use the extra_js_urls() or extra_body_script() plugin hooks to inject JavaScript into a page
Datasette instances with custom templates can include additional JavaScript in those templates
The extra_js_urls key in datasette.yaml can be used to include extra JavaScript
There are no limitations on what this JavaScript can do. It is executed directly by the browser, so it can manipulate the DOM, fetch additional data and do anything else that JavaScript is capable of.
Custom JavaScript has security implications, especially for authenticated Datasette instances where the JavaScript might run in the context of the authenticated user. It's important to carefully review any JavaScript you run in your Datasette instance.",154,
765,Table schema,"Use /database-name/table-name/-/schema to see the schema for a specific table. The .md and .json extensions work here too. The JSON returns an object with ""ok"" , ""database"" , ""table"" , and ""schema"" keys.",154,
764,Database schema,"Use /database-name/-/schema to see the complete schema for a specific database. The .md and .json extensions work here too. The JSON returns an object with ""ok"" , ""database"" and ""schema"" keys.",154,
763,Instance schema,"Access /-/schema to see the complete schema for all attached databases in the Datasette instance.
Use /-/schema.md to get the same information as Markdown.
Use /-/schema.json to get the same information as JSON, which looks like this:
{
""ok"": true,
""schemas"": [
{
""database"": ""content"",
""schema"": ""create table posts ...""
}
]
}",154,
762,Schemas,Datasette offers /-/schema endpoints to expose the SQL schema for databases and tables.,154,
761,Row,"Every row in every Datasette table has its own URL. This means individual records can be linked to directly.
Table cells with extremely long text contents are truncated on the table view according to the truncate_cells_html setting. If a cell has been truncated the full length version of that cell will be available on the row page.
Rows which are the targets of foreign key references from other tables will show a link to a filtered search for all records that reference that row. Here's an example from the Registers of Members Interests database:
../people/uk~2Eorg~2Epublicwhip~2Fperson~2F10001
Note that this URL includes the encoded primary key of the record.
Here's that same page as JSON:
../people/uk~2Eorg~2Epublicwhip~2Fperson~2F10001.json",154,
760,Table fragment,"The ///-/fragment endpoint returns the rendered table HTML
for rows matching the provided filters. It is used by Datasette's row editing
interface to refresh rows after changes while still respecting custom table
templates and render_cell plugin hooks.",154,
759,Table,"The table page is the heart of Datasette: it allows users to interactively explore the contents of a database table, including sorting, filtering, Full-text search and applying Facets .
The HTML interface is worth spending some time exploring. As with other pages, you can return the JSON data by appending .json to the URL path, before any ? query string arguments.
The query string arguments are described in more detail here: Table arguments
You can also use the table page to interactively construct a SQL query - by applying different filters and a sort order for example - and then click the ""View and edit SQL"" link to see the SQL query that was used for the page and edit and re-submit it.
Some examples:
../items lists all of the line-items registered by UK MPs as potential conflicts of interest. It demonstrates Datasette's support for Full-text search .
../antiquities-act%2Factions_under_antiquities_act is an interface for exploring the ""actions under the antiquities act"" data table published by FiveThirtyEight.
../global-power-plants?country_long=United+Kingdom&primary_fuel=Gas is a filtered table page showing every Gas power plant in the United Kingdom. It includes some default facets (configured using its metadata.json ) and uses the datasette-cluster-map plugin to show a map of the results.",154,
758,Stored query browsers,"The /-/queries page lists stored queries across every database visible to the current actor. The /database-name/-/queries page lists stored queries for a single database. The JSON versions accept ?_size= (default 50, max for the max_returned_rows limit) and a ?_next= pagination token.
These pages support search, pagination and filters for read-only or writable queries and private or public queries. Adding a .json extension to either URL returns the same list as JSON.",154,
757,Write SQL queries,"The /database-name/-/execute-write page can be used to execute SQL statements that write to a mutable database, if the execute-write-sql permission is enabled.
This page extracts named parameters from the SQL, shows the tables that will be affected and lists the permissions required before the query can be executed. It also includes templates for common INSERT , UPDATE and DELETE statements.
Datasette checks additional permissions based on the operations in the SQL. Row changes require the relevant table-level permissions such as insert-row , update-row and delete-row ; reads from source tables require view-table ; and schema changes require permissions such as create-table , alter-table or drop-table .
Use the Executing write SQL JSON API to execute writable SQL programmatically.",154,
756,Custom SQL queries,"The /database-name/-/query page can be used to execute an arbitrary SQL query against that database, if the execute-sql permission is enabled. This query is passed as the ?sql= query string parameter.
This means you can link directly to a query by constructing the following URL:
/database-name/-/query?sql=SELECT+*+FROM+table_name
Each configured stored query has its own page, at /database-name/query-name . Viewing this page will execute the query and display the results.
In both cases adding a .json extension to the URL will return the results as JSON.",154,
755,Queries,,154,
754,Hidden tables,"Some tables listed on the database page are treated as hidden. Hidden tables are not completely invisible - they can be accessed through the ""hidden tables"" link at the bottom of the page. They are hidden because they represent low-level implementation details which are generally not useful to end-users of Datasette.
The following tables are hidden by default:
Any table with a name that starts with an underscore - this is a Datasette convention to help plugins easily hide their own internal tables.
Tables that have been configured as ""hidden"": true using hidden .
*_fts tables that implement SQLite full-text search indexes.
Tables relating to the inner workings of the SpatiaLite SQLite extension.
sqlite_stat tables used to store statistics used by the query optimizer.",154,
753,Database,"Each database has a page listing the tables, views and stored queries available for that database. If the execute-sql permission is enabled (it's on by default) there will also be an interface for executing arbitrary SQL select queries against the data.
Examples:
fivethirtyeight.datasettes.com/fivethirtyeight
datasette.io/global-power-plants
The JSON version of this page provides programmatic access to the underlying data:
fivethirtyeight.datasettes.com/fivethirtyeight.json
datasette.io/global-power-plants.json
The returned object includes an ""ok"": true key alongside keys such as ""database"" , ""tables"" , ""views"" , ""queries"" and ""metadata"" .",154,
752,Top-level index,"The root page of any Datasette installation is an index page that lists all of the currently attached databases. Some examples:
fivethirtyeight.datasettes.com
register-of-members-interests.datasettes.com
Add /.json to the end of the URL for the JSON version of the underlying data:
fivethirtyeight.datasettes.com/.json
register-of-members-interests.datasettes.com/.json
The index page can also be accessed at /-/ , useful for if the default index page has been replaced using an index.html custom template . The /-/ page will always render the default Datasette index.html template.",154,
751,Pages and API endpoints,"The Datasette web application offers a number of different pages that can be accessed to explore the data in question, each of which is accompanied by an equivalent JSON API.",154,
750,/-/messages,"The debug tool at /-/messages can be used to set flash messages to try out that feature. See .add_message(request, message, type=datasette.INFO) for details of this feature.",154,
749,/-/actor,"Shows the currently authenticated actor. Useful for debugging Datasette authentication plugins.
{
""ok"": true,
""actor"": {
""id"": 1,
""username"": ""some-user""
}
}",154,
748,/-/threads,"Shows details of threads and asyncio tasks. This endpoint requires the permissions-debug permission, since it exposes runtime internals. Threads example :
{
""ok"": true,
""num_threads"": 2,
""threads"": [
{
""daemon"": false,
""ident"": 4759197120,
""name"": ""MainThread""
},
{
""daemon"": true,
""ident"": 123145319682048,
""name"": ""Thread-1""
},
],
""num_tasks"": 3,
""tasks"": [
"" cb=[set.discard()]>"",
"" wait_for=()]> cb=[run_until_complete..()]>"",
"" wait_for=()]>>""
]
}",154,
747,/-/debug/autocomplete,"The debug tool at /-/debug/autocomplete can be used to try out the autocomplete component against a specific table. Pass ?database=db&table=table to display an autocomplete field backed by that table's /-/autocomplete endpoint.
Without those query string arguments, the page lists up to five tables with detected label columns, scanning at most 100 tables.",154,
746,/-/jump,"Returns a JSON list of items that the current actor has permission to view for Datasette's jump menu. By default this includes visible databases, tables, views and stored queries, and plugins can contribute additional items.
Each item includes a type string used as a category label in the menu. Items can also include an optional description with longer text describing that individual result.
The endpoint supports a ?q= query parameter for filtering items by name.
Jump example :
{
""ok"": true,
""matches"": [
{
""name"": ""fixtures"",
""url"": ""/fixtures"",
""type"": ""database"",
""description"": null
},
{
""name"": ""fixtures: facetable"",
""url"": ""/fixtures/facetable"",
""type"": ""table"",
""description"": null
},
{
""name"": ""fixtures: recent_releases"",
""url"": ""/fixtures/recent_releases"",
""type"": ""query"",
""description"": null
}
],
""truncated"": false
}
Search example with ?q=facet returns only items matching .*facet.* :
{
""ok"": true,
""matches"": [
{
""name"": ""fixtures: facetable"",
""url"": ""/fixtures/facetable"",
""type"": ""table"",
""description"": null
}
],
""truncated"": false
}
When multiple search terms are provided (e.g., ?q=user+profile ), items must match the pattern .*user.*profile.* . Results are ordered by relevance, then by item type and shortest display name.",154,
745,/-/actions,"Shows all actions registered with the permission system, including those added by plugins. Requires the permissions-debug permission.
{
""ok"": true,
""actions"": [
{
""name"": ""view-instance"",
""abbr"": ""vi"",
""description"": ""View Datasette instance"",
""takes_parent"": false,
""takes_child"": false,
""resource_class"": null,
""also_requires"": null
}
]
}",154,
744,/-/databases,"Shows currently attached databases that the current actor is allowed to view, based on the view-database permission. Databases example :
{
""ok"": true,
""databases"": [
{
""hash"": null,
""is_memory"": false,
""is_mutable"": true,
""name"": ""fixtures"",
""path"": ""fixtures.db"",
""size"": 225280
}
]
}",154,
743,/-/config,"Shows the configuration for this instance of Datasette. This is generally the contents of the datasette.yaml or datasette.json file, which can include plugin configuration as well. Config example :
{
""ok"": true,
""settings"": {
""template_debug"": true,
""trace_debug"": true,
""force_https_urls"": true
}
}
Any keys that include the one of the following substrings in their names will be returned as redacted *** output, to help avoid accidentally leaking private configuration information: secret , key , password , token , hash , dsn .",154,
742,/-/settings,"Shows the Settings for this instance of Datasette. Settings example :
{
""ok"": true,
""default_facet_size"": 30,
""default_page_size"": 100,
""facet_suggest_time_limit_ms"": 50,
""facet_time_limit_ms"": 1000,
""max_returned_rows"": 1000,
""sql_time_limit_ms"": 1000
}",154,
741,/-/plugins,"Shows a list of currently installed plugins and their versions. Plugins example :
{
""ok"": true,
""plugins"": [
{
""name"": ""datasette_cluster_map"",
""static"": true,
""templates"": false,
""version"": ""0.10"",
""hooks"": [""extra_css_urls"", ""extra_js_urls"", ""extra_body_script""]
}
]
}
Add ?all=1 to include details of the default plugins baked into Datasette.",154,
740,/-/versions,"Shows the version of Datasette, Python and SQLite. Versions example :
{
""ok"": true,
""datasette"": {
""version"": ""0.60""
},
""python"": {
""full"": ""3.8.12 (default, Dec 21 2021, 10:45:09) \n[GCC 10.2.1 20210110]"",
""version"": ""3.8.12""
},
""sqlite"": {
""extensions"": {
""json1"": null
},
""fts_versions"": [
""FTS5"",
""FTS4"",
""FTS3""
],
""compile_options"": [
""COMPILER=gcc-6.3.0 20170516"",
""ENABLE_FTS3"",
""ENABLE_FTS4"",
""ENABLE_FTS5"",
""ENABLE_JSON1"",
""ENABLE_RTREE"",
""THREADSAFE=1""
],
""version"": ""3.37.0""
}
}",154,
739,/-/metadata,"Shows the contents of the metadata.json file that was passed to datasette serve , if any. Metadata example :
{
""license"": ""CC Attribution 4.0 License"",
""license_url"": ""http://creativecommons.org/licenses/by/4.0/"",
""source"": ""fivethirtyeight/data on GitHub"",
""source_url"": ""https://github.com/fivethirtyeight/data"",
""title"": ""Five Thirty Eight"",
""databases"": {
}
}",154,
738,Introspection,"Datasette includes some pages and JSON API endpoints for introspecting the current instance. These can be used to understand some of the internals of Datasette and to see how a particular instance has been configured.
Each of these pages can be viewed in your browser. Add .json to the URL to get back the contents as JSON.
JSON responses that return an object include an ""ok"": true key, consistent with the rest of the JSON API .
The introspection endpoints documented on this page are covered by the JSON API stability promise , with the exception of the debug endpoints /-/threads and /-/actions , whose shapes may change in future releases.",154,
737,Row page,"The page showing an individual row, e.g. /fixtures/facetable/1. Rendered using the row.html template.
Many of these keys are shared with the JSON API for this page.
alternate_url_json - str
URL for the JSON version of this page
columns - list
List of column names returned by this table, row or query.
custom_table_templates - list
Custom template names that were considered for displaying this row's table, in lookup order.
database - str
Database name
database_color - str
Color assigned to the database
display_columns - list
Column metadata used by the HTML table display. Each item includes name , sortable , is_pk , type , notnull , description , column_type and column_type_config keys.
display_rows - list
Rows formatted for the HTML table display. Each row is iterable and contains cell dictionaries with column , value , raw and value_type keys.
foreign_key_tables - list
List of tables that link to this row using foreign keys. Each item includes the foreign key fields plus count for matching rows and link for the filtered table URL.
metadata - dict
Metadata dictionary for the table, database or stored query. Table and row metadata include a columns dictionary mapping column names to descriptions; stored query metadata returns the stored query configuration.
ok - bool
True if the data for this page was retrieved without errors
primary_key_values - list
Values of the primary keys for this row, from the URL
primary_keys - list
List of primary key column names for this table, or an empty list if the table has no explicit primary key.
private - bool
Whether this resource is private to the current actor
query_ms - float
Time taken by the SQL queries for this page, in milliseconds
renderers - dict
Dictionary mapping output format names such as json to URLs for this row in that format.
row_actions - list
Row actions made available by core and plugin hooks. Each item is either a link with href , label and optional description keys, or a button with type: ""button"" , label , optional description and optional attrs . See Action hooks and row_actions(datasette, actor, request, database, table, row) .
row_mutation_ui - bool
True if the row edit/delete JavaScript UI should be enabled
rows - list
A single-item list containing this row as a dictionary mapping column name to raw value.
select_templates - list
List of template names that were considered for this page, with the selected template prefixed by * .
settings - dict
Dictionary of Datasette's current settings, keyed by setting name.
table - str
Table name
table_page_data - dict
JSON data used by JavaScript on the row page. Includes database , table and tableUrl , plus optional foreignKeys mapping column names to autocomplete URLs.
top_row - callable
Async callable that renders the top_row plugin slot for this row and returns HTML.
url_csv - str
URL for the CSV export of this page
url_csv_hidden_args - list
List of (name, value) pairs for hidden form fields used by the CSV export form, preserving current options while forcing _size=max .
url_csv_path - str
Path portion of the CSV export URL
[[[end]]]",154,
736,Table page,"The page showing the rows in a table or SQL view, e.g. /fixtures/facetable. Rendered using the table.html template.
Many of these keys are shared with the JSON API for this page.
actions - callable
Async callable returning table or view actions made available by core and plugin hooks. Each item is either a link with href , label and optional description keys, or a button with type: ""button"" , label , optional description and optional attrs . See Action hooks , table_actions(datasette, actor, database, table, request) and view_actions(datasette, actor, database, view, request) .
all_columns - list
List of all column names in the table, regardless of _col= or _nocol= filtering.
allow_execute_sql - bool
True if the current actor can execute custom SQL against this database
alternate_url_json - str
URL for the JSON version of this page
append_querystring - callable
Function append_querystring(url, querystring) that appends additional query string arguments to a URL, using ? or & as appropriate.
columns - list
List of column names returned by this table, row or query.
count - int
Total count of rows matching these filters
count_sql - str
SQL query string used to calculate the total count for the current table view, including active filters.
count_truncated - bool
True if count is a capped lower bound rather than an exact total, because Datasette stopped counting after its configured row-count limit.
custom_table_templates - list
List of custom template names considered for rendering table rows, in lookup order.
database - str
Database name
database_color - str
Color assigned to the database
datasette_allow_facet - str
The string ""true"" or ""false"" reflecting the allow_facet setting
display_columns - list
Column metadata used by the HTML table display. Each item includes name , sortable , is_pk , type , notnull , description , column_type and column_type_config keys.
display_rows - list
Rows formatted for the HTML table display. Each row is iterable and contains cell dictionaries with column , value , raw and value_type keys; table pages may also provide pk_path , row_path and row_label attributes on each row object.
expandable_columns - list
List of foreign key columns that can be expanded with labels. Each item is a (foreign_key, label_column) pair where foreign_key is the SQLite foreign key dictionary and label_column is the label column in the referenced table, or None .
extra_wheres_for_ui - list
Extra where clauses from ?_where= for display in the UI. Each item has text for the SQL fragment and remove_url for a URL that removes that fragment.
facet_results - dict
Results of facets calculated against this data. A dictionary with results and timed_out keys: results maps facet names to facet dictionaries with name , type , results and URL keys, and each facet result item includes value , label , count and toggle_url .
facets_timed_out - list
List of names of facet calculations that exceeded the facet time limit.
filter_columns - list
List of column names offered by the filter interface, including currently displayed columns and any hidden columns that can still be filtered.
filters - Filters
Filters object used by the HTML table interface. Useful methods include filters.human_description_en() ; this is not JSON serializable.
fix_path - callable
Function that applies the configured base_url prefix to a path.
form_hidden_args - list
List of (name, value) pairs for hidden form fields used by the HTML table interface to preserve current query string options.
human_description_en - str
Human-readable description of the filters
is_sortable - bool
True if any of the displayed columns can be used to sort
is_view - bool
Whether this resource is a view instead of a table
metadata - dict
Metadata dictionary for the table, database or stored query. Table and row metadata include a columns dictionary mapping column names to descriptions; stored query metadata returns the stored query configuration.
next - str
Pagination token for the next page, or None
next_url - str
Full URL for the next page of results, or None if there are no more pages. See Pagination .
ok - bool
True if the data for this page was retrieved without errors
path_with_replaced_args - callable
Function for building the current path with modified query string arguments. Pass the current request and a dictionary of argument names to replacement values, using None to remove an argument.
primary_keys - list
List of primary key column names for this table, or an empty list if the table has no explicit primary key.
private - bool
Whether this resource is private to the current actor
query - dict
Details of the underlying SQL query as a dictionary with sql and params keys.
query_ms - float
Time taken by the SQL queries for this page, in milliseconds
renderers - dict
Dictionary mapping output format names such as json or plugin-provided renderer names to URLs for this data in that format.
rows - list
The rows for this page, as a list of dictionaries mapping column name to raw value.
select_templates - list
List of template names that were considered for this page, with the selected template prefixed by * .
set_column_type_ui - dict
Information needed to build an interface for assigning column types, or None if unavailable. When present it has path and columns keys; columns maps column names to current and options values.
settings - dict
Dictionary of Datasette's current settings, keyed by setting name.
sort - str
Column the page is sorted by, or None
sort_desc - str
Column the page is sorted by in descending order, or None
sorted_facet_results - list
Facet result dictionaries sorted for display. Each item has the same shape as an entry from facet_results['results'] .
suggested_facets - list
Suggestions for facets that might return interesting results. Each item is a dictionary with name and toggle_url keys, and may include extra keys such as type or label depending on the facet class.
supports_search - bool
True if this table has full-text search configured
table - str
Table name
table_alter_ui - dict
Information needed to enable the alter table UI, or None if altering this table is not available to the current actor. When present it has path , tableName , columns , primaryKeys , columnTypes , defaultExpressions and foreignKeyTargetsPath keys, plus optional customColumnTypes and dropPath keys.
table_definition - str
SQL definition for this table
table_insert_ui - dict
Information needed to enable the row insertion UI, or None if row insertion is not available to the current actor. When present it has path , tableName , columns , bulkColumns , primaryKeys and maxInsertRows keys, plus optional upsertPath if the current actor has permission to update rows. columns lists columns for the single-row insert form, while bulkColumns lists columns for the bulk insert form. Each column includes name , sqlite_type , notnull , default , has_default , is_pk , is_auto_pk , value_kind and column_type keys.
table_page_data - dict
JSON data used by JavaScript on the table page. Includes database , table and tableUrl , plus optional foreignKeys mapping column names to autocomplete URLs, optional insertRow data and optional alterTable data.
top_table - callable
Async callable that renders the top_table plugin slot for this table or view and returns HTML.
url_csv - str
URL for the CSV export of this page
url_csv_hidden_args - list
List of (name, value) pairs for hidden form fields used by the CSV export form, preserving current filters while forcing _size=max .
url_csv_path - str
Path portion of the CSV export URL
view_definition - str
SQL definition for this view",154,
735,Query page,"The page for arbitrary SQL queries (/database/-/query?sql=...) and stored queries (/database/query-name). Rendered using the query.html template.
allow_execute_sql - bool
Boolean indicating if custom SQL can be executed
alternate_url_json - str
URL for alternate JSON version of this page
columns - list
List of result column names in the order they appear in display_rows and rows .
database - str
The name of the database being queried
database_color - str
The color of the database
db_is_immutable - bool
Boolean indicating if this database is immutable
display_rows - list
List of result rows formatted for HTML display. Each row is a list of rendered cell values in the same order as columns .
edit_sql_url - str
URL to edit the SQL for a stored query
editable - bool
Boolean indicating if the SQL can be edited
error - str
Any query error message
hide_sql - bool
Boolean indicating if the SQL should be hidden
metadata - dict
Metadata dictionary for the database or stored query. Stored query metadata may include options such as hide_sql , on_success_message and on_error_redirect .
named_parameter_values - dict
Dictionary of named SQL parameter values, keyed by parameter name without the leading : .
private - bool
Boolean indicating if this is a private database
query - dict
Dictionary describing the SQL query being executed, with sql and params keys.
query_actions - callable
Async callable returning action items for the query menu. Each item is either a link with href , label and optional description keys, or a button with type: ""button"" , label , optional description and optional attrs . See Action hooks and query_actions(datasette, actor, database, query_name, request, sql, params) .
renderers - dict
Dictionary mapping output format names such as json to URLs for this query in that format.
save_query_url - str
URL to save the current arbitrary SQL as a query
select_templates - list
List of template names that were considered for this page, with the selected template prefixed by * .
show_hide_hidden - str
Rendered hidden HTML preserving the current _hide_sql or _show_sql state.
show_hide_link - str
The URL to toggle showing/hiding the SQL
show_hide_text - str
The text for the show/hide SQL link
stored_query - str
The name of the stored query if this is a stored query
stored_query_write - bool
Boolean indicating if this is a stored query that allows writes
table_columns - dict
Dictionary mapping table names to lists of column names, used to power SQL autocomplete.
tables - list[DatabaseTable]
List of DatabaseTable objects describing tables in the database. Each item has name , columns , primary_keys , count , count_truncated , hidden , fts_table , foreign_keys and private attributes. count_truncated is true if count is a capped lower bound rather than an exact total.
top_query - callable
Async callable that renders the top_query plugin slot for this query and returns HTML.
top_stored_query - callable
Async callable that renders the top_stored_query plugin slot for stored queries and returns HTML.
url_csv - str
URL for CSV export",154,
734,Database page,"The page listing the tables, views and queries in a database, e.g. /fixtures. Rendered using the database.html template.
allow_download - bool
Boolean indicating if database download is allowed
allow_execute_sql - bool
Boolean indicating if custom SQL can be executed
alternate_url_json - str
URL for the alternate JSON version of this page
attached_databases - list
List of names of databases attached to this SQLite connection. This is only populated for the special /_memory database when Datasette is started with --crossdb for Cross-database queries .
database - str
The name of the database
database_actions - callable
Async callable returning action items for the database menu. Each item is either a link with href , label and optional description keys, or a button with type: ""button"" , label , optional description and optional attrs . See Action hooks and database_actions(datasette, actor, database, request) .
database_color - str
The color assigned to the database
database_page_data - dict
JSON data used by JavaScript on the database page. Currently {} or {""createTable"": {...}} where createTable includes path , foreignKeyTargetsPath , databaseName , columnTypes , defaultExpressions , canInsertRows and optional customColumnTypes .
editable - bool
Boolean indicating if the database is editable
hidden_count - int
Count of hidden tables
metadata - dict
Metadata dictionary for the database, such as title , description , license and source values from Datasette metadata.
path - str
The URL path to this database
private - bool
Boolean indicating if this is a private database
queries - list[StoredQuery]
List of StoredQuery objects. Each has attributes including name , sql , title , description , description_html , hide_sql , fragment , parameters , is_write and private .
queries_count - int
Count of visible stored queries
queries_more - bool
Boolean indicating if more stored queries are available
select_templates - list
List of template names that were considered for this page, with the selected template prefixed by * .
show_hidden - str
Value of _show_hidden query parameter
size - int
The size of the database in bytes
table_columns - dict
Dictionary mapping table names to lists of column names, used to power SQL autocomplete.
tables - list[DatabaseTable]
List of DatabaseTable objects describing tables in the database. Each item has name , columns , primary_keys , count , count_truncated , hidden , fts_table , foreign_keys and private attributes. count_truncated is true if count is a capped lower bound rather than an exact total.
top_database - callable
Async callable that renders the top_database plugin slot for this database and returns HTML.
views - list[DatabaseViewInfo]
List of DatabaseViewInfo objects describing SQLite views in the database. Each item has name and private attributes.",154,
733,Base context,"These variables are available on every page rendered by Datasette, including pages rendered by plugins that use datasette.render_template() . Plugins can add additional variables using the extra_template_vars(template, database, table, columns, view_name, request, datasette) hook.
request
The current Request object , or None. Common properties include request.path , request.args , request.actor , request.url_vars and request.host .
crumb_items
Async function returning breadcrumb navigation items for the current page. Call it with request=request plus optional database= and table= arguments; it returns a list of {""href"": url, ""label"": label} dictionaries.
urls
Object with methods for constructing URLs within Datasette. Common methods include urls.instance() , urls.database(database) , urls.table(database, table) , urls.query(database, query) , urls.row(database, table, row_path) and urls.static(path) - see datasette.urls .
actor
The currently authenticated actor dictionary, or None. Actors usually include an id key and may include any other keys supplied by authentication plugins.
menu_links
Async function returning links for the Datasette application menu, including links added by plugins. Each item is a link dictionary with href and label keys. See menu_links(datasette, actor, request) ; for page action menus that can also include JavaScript-backed buttons, see Action hooks .
display_actor
Function that accepts an actor dictionary and returns the display string used in the navigation menu.
show_logout
True if the logout link should be shown in the navigation menu
zip
Python's zip() builtin, made available to template logic
body_scripts
List of JavaScript snippets contributed by plugins using extra_body_script(template, database, table, columns, view_name, request, datasette) . Each item is a dictionary with script containing JavaScript source and module indicating whether Datasette will wrap it in