Datasette Cloud API documentation
Each Datasette Cloud space includes a JSON API for both accessing and modifying data hosted within that space.
See Getting started with the Datasette Cloud API for a tutorial introduction to the API, showing how it can be used to automatically import data from the US government Federal Register into Datasette Cloud.
The JSON API is described in detail in the Datasette 1.0 alpha documentation.
This page provides details that are specific to the Datasette Cloud implementation of the API.
Use-cases
The Datasette Cloud API can be used for a wide range of tasks, including:
- Importing data into a space. Create a token with the ability to write data to one or more tables, then use that token from an automation platform such as GitHub Actions to import new data on a schedule.
- Exporting data from a space. Tokens that can read specific tables or that have the
execute-sql
permission can be used to export data as JSON or CSV. - Building custom visualizations. Datasette's JSON API is a great fit for working with visualization tools such as Observable notebooks. Create a read-only token for the data you need to access, then use that token to fetch the data for your custom visualization directly from the API.
- Data cleanup and annotation. An API integration can read data from Datasette Cloud, process that data and then write the results back to the same or to a different table.
Authentication
Any calls you make to the Datasette Cloud API - for both reading and writing data - must include an Authorization: Bearer <token>
header containing a valid API token.
These tokens can be created and revoked from the API tokens page within your Datasette Cloud space.
Tokens you create will be able to act on your behalf - any action your user account can perform within a space - creating tables, inserting and updating rows, etc - will be inherited by the token.
You can limit the token to a subset of those abilities when you create it. For example, you could create a token that can only read data from a particular table.
Tokens can also be created with a limited lifespan - for example, you can create a token that expires in 2 hours.
This is good practice if you are creating a token to use for a specific, short-lived task, as opposed to tokens that will be used for long-running automations.