Skip to content

Commit

Permalink
documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
asg017 committed Sep 13, 2023
1 parent 2a05f97 commit 740c9f2
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 9 deletions.
97 changes: 94 additions & 3 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,101 @@
.. _configuration:

Configuration
========
=============

Datasette offers many way to configure your Datasette instances: server settings, plugin configuration, authentication, and more.
Datasette offers several ways to configure your Datasette instances: server settings, plugin configuration, authentication, and more.

To facilitate this, You can provide a `datasette.yaml` configuration file to datasette with the ``--config``/ ``-c`` flag:
To facilitate this, You can provide a ``datasette.yaml`` configuration file to datasette with the ``--config``/ ``-c`` flag:

.. code-block:: bash
datasette mydatabase.db --config datasette.yaml
.. _configuration_reference:

``datasette.yaml`` Reference
------------------------

Here's a full example of all the valid configuration options that can exist inside ``datasette.yaml``.

.. tab:: YAML

.. code-block:: yaml
# Datasette settings block
settings:
default_page_size: 50
sql_time_limit_ms: 3500
max_returned_rows: 2000
# top-level plugin configuration
plugins:
datasette-my-plugin:
key: valueA
# Database and table-level configuration
databases:
your_db_name:
# plugin configuration for the your_db_name database
plugins:
datasette-my-plugin:
key: valueA
tables:
your_table_name:
# plugin configuration for the your_table_name table
# inside your_db_name database
plugins:
datasette-my-plugin:
key: valueB
Settings Configuration
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

:ref:`settings` can be configured in ``datasette.yaml`` with the ``settings`` key.

.. tab:: YAML

.. code-block:: yaml
# inside datasette.yaml
settings:
default_allow_sql: off
default_page_size: 50
.. _configuration_reference_plugins:
Plugin Configuration
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Configuration for plugins can be defined inside ``datasette.yaml``. For top-level plugin configuration, use the ``plugins`` key.

.. tab:: YAML

.. code-block:: yaml
# inside datasette.yaml
plugins:
datasette-my-plugin:
key: my_value
For database level or table level plugin configuration, nest it under the appropriate place under ``databases``.

.. tab:: YAML

.. code-block:: yaml
# inside datasette.yaml
databases:
my_database:
# plugin configuration for the my_database database
plugins:
datasette-my-plugin:
key: my_value
my_other_database:
tables:
my_table:
# plugin configuration for the my_table table inside the my_other_database database
plugins:
datasette-my-plugin:
key: my_value
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,4 @@ Contents
internals
contributing
changelog
configuration
2 changes: 1 addition & 1 deletion docs/internals.rst
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ The dictionary keys are the permission names - e.g. ``view-instance`` - and the
``table`` - None or string
The table the user is interacting with.

This method lets you read plugin configuration values that were set in ``metadata.json``. See :ref:`writing_plugins_configuration` for full details of how this method should be used.
This method lets you read plugin configuration values that were set in ``datasette.yaml``. See :ref:`writing_plugins_configuration` for full details of how this method should be used.

The return value will be the value from the configuration file - usually a dictionary.

Expand Down
2 changes: 1 addition & 1 deletion docs/plugin_hooks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ Potential use-cases:

* Run some initialization code for the plugin
* Create database tables that a plugin needs on startup
* Validate the metadata configuration for a plugin on startup, and raise an error if it is invalid
* Validate the configuration for a plugin on startup, and raise an error if it is invalid

.. note::

Expand Down
9 changes: 5 additions & 4 deletions docs/writing_plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ This will return the ``{"latitude_column": "lat", "longitude_column": "lng"}`` i

If there is no configuration for that plugin, the method will return ``None``.

If it cannot find the requested configuration at the table layer, it will fall back to the database layer and then the root layer. For example, a user may have set the plugin configuration option like so:
If it cannot find the requested configuration at the table layer, it will fall back to the database layer and then the root layer. For example, a user may have set the plugin configuration option inside ``datasette.yaml`` like so:

.. [[[cog
from metadata_doc import metadata_example
Expand All @@ -206,6 +206,7 @@ If it cannot find the requested configuration at the table layer, it will fall b

.. code-block:: yaml
# inside datasette.yaml
databases:
sf-trees:
plugins:
Expand Down Expand Up @@ -234,7 +235,7 @@ If it cannot find the requested configuration at the table layer, it will fall b
In this case, the above code would return that configuration for ANY table within the ``sf-trees`` database.

The plugin configuration could also be set at the top level of ``metadata.yaml``:
The plugin configuration could also be set at the top level of ``datasette.yaml``:

.. [[[cog
metadata_example(cog, {
Expand All @@ -252,7 +253,7 @@ The plugin configuration could also be set at the top level of ``metadata.yaml``

.. code-block:: yaml
title: This is the top-level title in metadata.json
title: This is the top-level title in datasette.yaml
plugins:
datasette-cluster-map:
latitude_column: xlat
Expand All @@ -264,7 +265,7 @@ The plugin configuration could also be set at the top level of ``metadata.yaml``
.. code-block:: json
{
"title": "This is the top-level title in metadata.json",
"title": "This is the top-level title in datasette.json",
"plugins": {
"datasette-cluster-map": {
"latitude_column": "xlat",
Expand Down

0 comments on commit 740c9f2

Please sign in to comment.