Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

datasette-charts

PyPI Changelog Tests License

Suggests charts for any Datasette table, view or SQL query, and lets you build your own.

This is an early version of the design in spec.md: enough to try the idea out against small tables and queries. See What is not built yet.

Requirements

This needs a Datasette newer than 1.0a43: commit 56e02c1 or later, which is not yet in a release. Until it is, run against a checkout of Datasette's main branch. From a checkout of this repository:

uv run --no-project --with-editable ~/dev/datasette --with-editable . datasette content.db

--no-project matters here. Without it, uv also installs the latest stable Datasette into this project's own environment, and that copy is the one that gets imported.

Installation

Install this plugin in the same environment as Datasette.

datasette install datasette-charts

Usage

Every table, view and SQL query page gets a Charts panel at the top. It shows a row of suggested charts, best first, each with a thumbnail, a title and the reason it was suggested. Select one to see it at full size.

Beside the full-size chart is a builder for changing the chart type, columns, aggregates, time units and bins. "Build a chart" at the end of the row starts from scratch. Anything the plugin can suggest can be built by hand.

The chart you are looking at is kept in the page's URL fragment, so the address bar always holds a link to it.

When nothing is suggested for a table, the panel starts collapsed. Opening it still offers "Build a chart".

Charts never fetch every row. Each one compiles to a SQL query that returns a small, aggregated result, and that query is what "View and edit this chart's SQL" links to.

Filters and facets

On a filtered table page the charts cover the rows the page shows. Column filters such as ?state=CA and ?price__gt=5, ?_search=, ?_where= and ?_through= all apply, and so does anything you click in a facet. The suggestions are worked out again for the filtered rows, so a column that the filter has narrowed to a single value is no longer suggested.

The chart you select stays selected as you filter, facet, sort and page through a table: each new page opens with the same chart, now drawn from that page's rows. Close the chart to stop it coming back. This is remembered per table, in the browser tab.

Chart types

Type Shows Suggested when
histogram The distribution of a numeric column, on a log scale when it has a long tail A measure has spread
bar A count or an aggregate for each value of a category: the top N plus "Other" A category has a workable number of values
line A count or an aggregate over time, optionally split into series A date or timestamp column spans several buckets
scatter Two numeric columns: points for small sources, a binned heatmap for large ones There are two measures
map Latitude and longitude: points for small sources, grid cells for large ones A latitude/longitude pair exists
stacked_bar Stacked or grouped bars for two categories, or a category over time There are two categories

How large sources are handled

Suggestions come from a profile of the source: row count, types, distinct counts, top values, ranges and detected dates. Profiling runs inline, under Datasette's SQL time limit.

  • A source of up to 50,000 rows (and 1,000,000 cells) is profiled in full.
  • A larger one is profiled from a sample of up to 10,000 rows. The panel says so when this happens. Charts still query every row.
  • For a table, the sample is spread evenly across its rows. For a view, a query or a filtered table it is the first rows the source returns, which can be less representative.

To let more work happen inline, raise Datasette's time limit and the plugin's limits together:

datasette data.db --setting sql_time_limit_ms 10000 -c datasette.yaml
plugins:
  datasette-charts:
    inline_row_limit: 5000000
    inline_cell_limit: 100000000

Configuration

All settings are optional. These are the defaults:

plugins:
  datasette-charts:
    max_suggestions: 8
    inline_row_limit: 50000       # profile the whole source up to this many rows...
    inline_cell_limit: 1000000    # ...and this many rows x columns
    sample_rows: 10000            # sample size for larger sources
    temporal_min_match_rate: 0.95 # share of values that must look like dates
    thumbnail_row_limit: 100000   # above this, thumbnails load on hover
    thumbnail_concurrency: 2
    hard_max_rows: 5000           # cap on the rows any chart query returns
    distinct_cap: 1000
    top_values: 20
    profile_budget_ms: null       # default: twice sql_time_limit_ms, at least 5000
    chart_time_limit_ms: null     # default: sql_time_limit_ms
    profile_cache_seconds: 300    # profiles are kept in memory this long
    auto_suggest: true            # false: wait until the panel is opened

Dates are detected from values: ISO 8601 dates and datetimes always, and Unix timestamps and years when the column name or declared type also suggests a time. To correct a column, set its kind in table-level configuration, or false to say it is not a time:

databases:
  shop:
    tables:
      orders:
        plugins:
          datasette-charts:
            temporal:
              shipped: unix_seconds
              build_number: false

The kinds are iso_date, iso_datetime, unix_seconds, unix_ms and year.

Permissions

  • Charts for a table or view need view-table. They do not need execute-sql.
  • Charts for a SQL query need execute-sql.
  • Charts for a stored query need view-query.
  • The compiled SQL is only shown to actors with execute-sql.

Command line

datasette charts suggest data.db orders
datasette charts suggest data.db --sql "select * from orders where state = :s" -p s CA
datasette charts profile data.db orders

suggest prints the ranked suggestions with the signals behind each score. profile prints the facts gathered about each column. Both take --json, and --time-limit-ms 10000 to run with a longer SQL time limit.

HTTP API

Endpoint Returns
/-/charts/types.json The registered chart types
/<db>/<table>/-/charts/suggest.json Suggestions for a table or view
/<db>/-/charts/suggest.json?sql=... Suggestions for a SQL query
/<db>/-/charts/data.json?source=...&spec=... The rows for one chart
/<db>/-/charts/profile.json?source=... The profile of a source

source is a JSON object such as {"kind": "table", "table": "orders"} or {"kind": "query", "sql": "...", "params": {}}.

A filtered table is a table source with the filters from the table page's query string as pairs: {"kind": "table", "table": "orders", "filters": [["state", "CA"], ["price__gt", "5"]]}. The table's own suggestions endpoint takes that query string directly, so /<db>/<table>/-/charts/suggest.json?state=CA&price__gt=5 means the same rows as the table page with those parameters, and its response includes the source to pass to data.json.

spec is a chart in the JSON format the suggestions use:

{
  "v": 1,
  "type": "line",
  "encoding": {
    "x": {"column": "created_at", "timeUnit": "month"},
    "y": {"aggregate": "count"},
    "series": {"column": "status", "limit": 5, "other": true}
  },
  "options": {}
}

Adding chart types

A chart type is a Python class that proposes charts and compiles them to SQL, plus a JavaScript module that draws the result. Other plugins register theirs with the register_chart_types hook, which is how the built-in ones are registered too:

from datasette import hookimpl
from datasette_charts import ChartType


class SankeyChart(ChartType):
    name = "sankey"
    ...


@hookimpl
def register_chart_types(datasette):
    return [SankeyChart]

The built-in chart types in datasette_charts/chart_types/ are the reference for now. This interface is not stable yet.

What is not built yet

From the spec, in rough order of how much it matters:

  • The background full tier and stored profiles. Nothing is written to the internal database and no background task runs. Profiles are kept in memory for a few minutes. A source too large to profile under the time limit gets suggestions from a sample, or none.
  • The verify stage. Candidates go straight from propose to rank, so nothing checks whether a time series is flat or two measures are related.
  • Precomputed thumbnails. Every thumbnail runs its query when it scrolls into view.
  • The snapshot harness, contact sheet and benchmarks.
  • Magic parameters in stored queries, such as :_actor_id.

The map draws points over a coarse world land outline, which needs no network access. The spec leaves the choice of basemap open.

Charts are drawn with Observable Plot, which is bundled along with D3. See datasette_charts/static/vendor/README.md for versions and licenses.

Development

To set up this plugin locally, first checkout the code. You can confirm it is available like this:

cd datasette-charts
# Confirm the plugin is visible
uv run --no-project --with-editable ~/dev/datasette --with-editable . datasette plugins

To run the tests, which also need Datasette's main branch for now:

uv run --no-project --with-editable ~/dev/datasette --with-editable . \
  --with pytest --with pytest-asyncio pytest

Metadata

Release files for datasette-charts 0.1a0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for datasette-charts 0.1a0
File Size Uploaded Provenance Actions
datasette_charts-0.1a0.tar.gz 281.4 kB With provenance Details for datasette_charts-0.1a0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for datasette-charts 0.1a0
File Interpreter ABI Platform Actions
datasette_charts-0.1a0-py3-none-any.whl Python 3 none any Details for datasette_charts-0.1a0-py3-none-any.whl

Total release size: 563.0 kB

Release files / datasette_charts-0.1a0.tar.gz

Download URL datasette_charts-0.1a0.tar.gz
Size 281.4 kB
Tags Source
SHA-256 checksum
How to use checksums
cec2a56ea133690ff0d23b3587c29e1e27d0ef507ac5a2fa833d936dd54d4543
BLAKE2b-256 checksum
How to use checksums
773dc6eb4f332925ff44069158ba3201b4a52e3177d5e5e5f87643c1087aef66
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

Release files / datasette_charts-0.1a0-py3-none-any.whl

Download URL datasette_charts-0.1a0-py3-none-any.whl
Size 281.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4c9313d80c41df90c3d5def70c37e1255278d3d0918783fc38a75ccc9ea5985d
BLAKE2b-256 checksum
How to use checksums
ade075b298dd14bb466ffc2a6913d8011aad73036cd2dd5c16b8baf46f4b8afe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

Security for datasette-charts 0.1a0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for datasette_charts-0.1a0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page