Populate docs/ from 0.65.2

This commit is contained in:
Automated 2025-11-05 18:51:58 +00:00
commit 264bba5db2
26 changed files with 883 additions and 5641 deletions

View file

@ -4,56 +4,27 @@ Metadata
========
Data loves metadata. Any time you run Datasette you can optionally include a
YAML or JSON file with metadata about your databases and tables. Datasette will then
JSON file with metadata about your databases and tables. Datasette will then
display that information in the web UI.
Run Datasette like this::
datasette database1.db database2.db --metadata metadata.yaml
datasette database1.db database2.db --metadata metadata.json
Your ``metadata.yaml`` file can look something like this:
Your ``metadata.json`` file can look something like this:
.. code-block:: json
.. [[[cog
from metadata_doc import metadata_example
metadata_example(cog, {
{
"title": "Custom title for your index page",
"description": "Some description text can go here",
"license": "ODbL",
"license_url": "https://opendatacommons.org/licenses/odbl/",
"source": "Original Data Source",
"source_url": "http://example.com/"
})
.. ]]]
}
.. tab:: metadata.yaml
.. code-block:: yaml
title: Custom title for your index page
description: Some description text can go here
license: ODbL
license_url: https://opendatacommons.org/licenses/odbl/
source: Original Data Source
source_url: http://example.com/
.. tab:: metadata.json
.. code-block:: json
{
"title": "Custom title for your index page",
"description": "Some description text can go here",
"license": "ODbL",
"license_url": "https://opendatacommons.org/licenses/odbl/",
"source": "Original Data Source",
"source_url": "http://example.com/"
}
.. [[[end]]]
Choosing YAML over JSON adds support for multi-line strings and comments.
You can optionally use YAML instead of JSON, see :ref:`metadata_yaml`.
The above metadata will be displayed on the index page of your Datasette-powered
site. The source and license information will also be included in the footer of
@ -66,14 +37,15 @@ instead.
Per-database and per-table metadata
-----------------------------------
Metadata at the top level of the file will be shown on the index page and in the
Metadata at the top level of the JSON will be shown on the index page and in the
footer on every page of the site. The license and source is expected to apply to
all of your data.
You can also provide metadata at the per-database or per-table level, like this:
.. [[[cog
metadata_example(cog, {
.. code-block:: json
{
"databases": {
"database1": {
"source": "Alternative source",
@ -87,45 +59,7 @@ You can also provide metadata at the per-database or per-table level, like this:
}
}
}
})
.. ]]]
.. tab:: metadata.yaml
.. code-block:: yaml
databases:
database1:
source: Alternative source
source_url: http://example.com/
tables:
example_table:
description_html: Custom <em>table</em> description
license: CC BY 3.0 US
license_url: https://creativecommons.org/licenses/by/3.0/us/
.. tab:: metadata.json
.. code-block:: json
{
"databases": {
"database1": {
"source": "Alternative source",
"source_url": "http://example.com/",
"tables": {
"example_table": {
"description_html": "Custom <em>table</em> description",
"license": "CC BY 3.0 US",
"license_url": "https://creativecommons.org/licenses/by/3.0/us/"
}
}
}
}
}
.. [[[end]]]
}
Each of the top-level metadata fields can be used at the database and table level.
@ -151,8 +85,9 @@ Column descriptions
You can include descriptions for your columns by adding a ``"columns": {"name-of-column": "description-of-column"}`` block to your table metadata:
.. [[[cog
metadata_example(cog, {
.. code-block:: json
{
"databases": {
"database1": {
"tables": {
@ -165,46 +100,53 @@ You can include descriptions for your columns by adding a ``"columns": {"name-of
}
}
}
})
.. ]]]
.. tab:: metadata.yaml
.. code-block:: yaml
databases:
database1:
tables:
example_table:
columns:
column1: Description of column 1
column2: Description of column 2
.. tab:: metadata.json
.. code-block:: json
{
"databases": {
"database1": {
"tables": {
"example_table": {
"columns": {
"column1": "Description of column 1",
"column2": "Description of column 2"
}
}
}
}
}
}
.. [[[end]]]
}
These will be displayed at the top of the table page, and will also show in the cog menu for each column.
You can see an example of how these look at `latest.datasette.io/fixtures/roadside_attractions <https://latest.datasette.io/fixtures/roadside_attractions>`__.
Specifying units for a column
-----------------------------
Datasette supports attaching units to a column, which will be used when displaying
values from that column. SI prefixes will be used where appropriate.
Column units are configured in the metadata like so:
.. code-block:: json
{
"databases": {
"database1": {
"tables": {
"example_table": {
"units": {
"column1": "metres",
"column2": "Hz"
}
}
}
}
}
}
Units are interpreted using Pint_, and you can see the full list of available units in
Pint's `unit registry`_. You can also add `custom units`_ to the metadata, which will be
registered with Pint:
.. code-block:: json
{
"custom_units": [
"decibel = [] = dB"
]
}
.. _Pint: https://pint.readthedocs.io/
.. _unit registry: https://github.com/hgrecco/pint/blob/master/pint/default_en.txt
.. _custom units: http://pint.readthedocs.io/en/latest/defining.html
.. _metadata_default_sort:
Setting a default sort order
@ -212,8 +154,9 @@ Setting a default sort order
By default Datasette tables are sorted by primary key. You can over-ride this default for a specific table using the ``"sort"`` or ``"sort_desc"`` metadata properties:
.. [[[cog
metadata_example(cog, {
.. code-block:: json
{
"databases": {
"mydatabase": {
"tables": {
@ -223,41 +166,13 @@ By default Datasette tables are sorted by primary key. You can over-ride this de
}
}
}
})
.. ]]]
.. tab:: metadata.yaml
.. code-block:: yaml
databases:
mydatabase:
tables:
example_table:
sort: created
.. tab:: metadata.json
.. code-block:: json
{
"databases": {
"mydatabase": {
"tables": {
"example_table": {
"sort": "created"
}
}
}
}
}
.. [[[end]]]
}
Or use ``"sort_desc"`` to sort in descending order:
.. [[[cog
metadata_example(cog, {
.. code-block:: json
{
"databases": {
"mydatabase": {
"tables": {
@ -267,36 +182,7 @@ Or use ``"sort_desc"`` to sort in descending order:
}
}
}
})
.. ]]]
.. tab:: metadata.yaml
.. code-block:: yaml
databases:
mydatabase:
tables:
example_table:
sort_desc: created
.. tab:: metadata.json
.. code-block:: json
{
"databases": {
"mydatabase": {
"tables": {
"example_table": {
"sort_desc": "created"
}
}
}
}
}
.. [[[end]]]
}
.. _metadata_page_size:
@ -305,8 +191,9 @@ Setting a custom page size
Datasette defaults to displaying 100 rows per page, for both tables and views. You can change this default page size on a per-table or per-view basis using the ``"size"`` key in ``metadata.json``:
.. [[[cog
metadata_example(cog, {
.. code-block:: json
{
"databases": {
"mydatabase": {
"tables": {
@ -316,36 +203,7 @@ Datasette defaults to displaying 100 rows per page, for both tables and views. Y
}
}
}
})
.. ]]]
.. tab:: metadata.yaml
.. code-block:: yaml
databases:
mydatabase:
tables:
example_table:
size: 10
.. tab:: metadata.json
.. code-block:: json
{
"databases": {
"mydatabase": {
"tables": {
"example_table": {
"size": 10
}
}
}
}
}
.. [[[end]]]
}
This size can still be over-ridden by passing e.g. ``?_size=50`` in the query string.
@ -358,8 +216,9 @@ Datasette allows any column to be used for sorting by default. If you need to
control which columns are available for sorting you can do so using the optional
``sortable_columns`` key:
.. [[[cog
metadata_example(cog, {
.. code-block:: json
{
"databases": {
"database1": {
"tables": {
@ -372,41 +231,7 @@ control which columns are available for sorting you can do so using the optional
}
}
}
})
.. ]]]
.. tab:: metadata.yaml
.. code-block:: yaml
databases:
database1:
tables:
example_table:
sortable_columns:
- height
- weight
.. tab:: metadata.json
.. code-block:: json
{
"databases": {
"database1": {
"tables": {
"example_table": {
"sortable_columns": [
"height",
"weight"
]
}
}
}
}
}
.. [[[end]]]
}
This will restrict sorting of ``example_table`` to just the ``height`` and
``weight`` columns.
@ -415,8 +240,9 @@ You can also disable sorting entirely by setting ``"sortable_columns": []``
You can use ``sortable_columns`` to enable specific sort orders for a view called ``name_of_view`` in the database ``my_database`` like so:
.. [[[cog
metadata_example(cog, {
.. code-block:: json
{
"databases": {
"my_database": {
"tables": {
@ -429,41 +255,7 @@ You can use ``sortable_columns`` to enable specific sort orders for a view calle
}
}
}
})
.. ]]]
.. tab:: metadata.yaml
.. code-block:: yaml
databases:
my_database:
tables:
name_of_view:
sortable_columns:
- clicks
- impressions
.. tab:: metadata.json
.. code-block:: json
{
"databases": {
"my_database": {
"tables": {
"name_of_view": {
"sortable_columns": [
"clicks",
"impressions"
]
}
}
}
}
}
.. [[[end]]]
}
.. _label_columns:
@ -478,8 +270,9 @@ column should be used as the link label.
If your table has more than two columns you can specify which column should be
used for the link label with the ``label_column`` property:
.. [[[cog
metadata_example(cog, {
.. code-block:: json
{
"databases": {
"database1": {
"tables": {
@ -489,36 +282,7 @@ used for the link label with the ``label_column`` property:
}
}
}
})
.. ]]]
.. tab:: metadata.yaml
.. code-block:: yaml
databases:
database1:
tables:
example_table:
label_column: title
.. tab:: metadata.json
.. code-block:: json
{
"databases": {
"database1": {
"tables": {
"example_table": {
"label_column": "title"
}
}
}
}
}
.. [[[end]]]
}
.. _metadata_hiding_tables:
@ -528,106 +292,54 @@ Hiding tables
You can hide tables from the database listing view (in the same way that FTS and
SpatiaLite tables are automatically hidden) using ``"hidden": true``:
.. [[[cog
metadata_example(cog, {
.. code-block:: json
{
"databases": {
"database1": {
"tables": {
"example_table": {
"hidden": True
"hidden": true
}
}
}
}
})
.. ]]]
}
.. tab:: metadata.yaml
.. _metadata_yaml:
.. code-block:: yaml
Using YAML for metadata
-----------------------
databases:
database1:
tables:
example_table:
hidden: true
Datasette accepts YAML as an alternative to JSON for your metadata configuration file. YAML is particularly useful for including multiline HTML and SQL strings.
Here's an example of a ``metadata.yml`` file, reusing an example from :ref:`canned_queries`.
.. tab:: metadata.json
.. code-block:: yaml
.. code-block:: json
title: Demonstrating Metadata from YAML
description_html: |-
<p>This description includes a long HTML string</p>
<ul>
<li>YAML is better for embedding HTML strings than JSON!</li>
</ul>
license: ODbL
license_url: https://opendatacommons.org/licenses/odbl/
databases:
fixtures:
tables:
no_primary_key:
hidden: true
queries:
neighborhood_search:
sql: |-
select neighborhood, facet_cities.name, state
from facetable join facet_cities on facetable.city_id = facet_cities.id
where neighborhood like '%' || :text || '%' order by neighborhood;
title: Search neighborhoods
description_html: |-
<p>This demonstrates <em>basic</em> LIKE search
{
"databases": {
"database1": {
"tables": {
"example_table": {
"hidden": true
}
}
}
}
}
.. [[[end]]]
The ``metadata.yml`` file is passed to Datasette using the same ``--metadata`` option::
.. _metadata_reference:
Metadata reference
------------------
A full reference of every supported option in a ``metadata.json`` or ``metadata.yaml`` file.
Top-level metadata
~~~~~~~~~~~~~~~~~~
"Top-level" metadata refers to fields that can be specified at the root level of a metadata file. These attributes are meant to describe the entire Datasette instance.
The following are the full list of allowed top-level metadata fields:
- ``title``
- ``description``
- ``description_html``
- ``license``
- ``license_url``
- ``source``
- ``source_url``
Database-level metadata
~~~~~~~~~~~~~~~~~~~~~~~
"Database-level" metadata refers to fields that can be specified for each database in a Datasette instance. These attributes should be listed under a database inside the `"databases"` field.
The following are the full list of allowed database-level metadata fields:
- ``source``
- ``source_url``
- ``license``
- ``license_url``
- ``about``
- ``about_url``
Table-level metadata
~~~~~~~~~~~~~~~~~~~~
"Table-level" metadata refers to fields that can be specified for each table in a Datasette instance. These attributes should be listed under a specific table using the `"tables"` field.
The following are the full list of allowed table-level metadata fields:
- ``source``
- ``source_url``
- ``license``
- ``license_url``
- ``about``
- ``about_url``
- ``hidden``
- ``sort/sort_desc``
- ``size``
- ``sortable_columns``
- ``label_column``
- ``facets``
- ``fts_table``
- ``fts_pk``
- ``searchmode``
- ``columns``
datasette fixtures.db --metadata metadata.yml