Skip to content
silverpoint
Documentation menu

New in 0.11

Python: notebooks, Flask, Django

New with silverpoint 0.11. silverpoint on PyPI draws any chart a table can feed from a pandas, polars, pyarrow or Spark table: as the value of a notebook cell, in a Flask or Django template, or as a self-contained HTML file. It builds the chart spec in Python and @silverpoint/embed's standalone file, vendored, draws it.

Try it

Three charts from three pandas DataFrames. The frame below is a plain page holding exactly what to_html(full_document=False) returned for each chart: no picture is made in Python. Hover or focus a chart and move with the arrow keys. Open the page on its own.

python
import pandas as pd
import silverpoint

wins = pd.DataFrame({"team": ["North", "South", "East", "West"], "wins": [12, 9, 15, 7]})
hits = pd.DataFrame({
    "hour": ["00", "04", "08", "12", "16", "20"],
    "hits": [18, 11, 34, 71, 74, 62],
})
load = pd.DataFrame({
    "day": ["Mon", "Mon", "Mon", "Tue", "Tue", "Tue", "Wed", "Wed", "Wed"],
    "slot": ["am", "noon", "pm"] * 3,
    "load": [3, 7, 5, 2, 8, 6, 4, 9, 3],
})

charts = [
    silverpoint.bar_chart(wins, x="team", value="wins", orientation="rows", title="Wins per team", width=420),
    silverpoint.line_chart(hits, x="hour", value="hits", title="Hits per hour", curve="monotone",
                           ground="cyanotype", substrate="prussian", width=420),
    silverpoint.heatmap_chart(load, row="day", column="slot", value="load", title="Load",
                              palette="sepia", width=420),
]
fragments = [chart.to_html(full_document=False, render="client") for chart in charts]

Install

silverpoint needs Python 3.10+ and has no dependencies. The flask and django extras bring the framework. silverpoint X.Y.Z vendors @silverpoint/embed X.Y.Z, version for version (silverpoint.SILVERPOINT_VERSION): the same engine as the React, Vue and Angular adapters, so the same picture, keyboard reading and precision mode.

shell
pip install silverpoint            # no dependencies
pip install "silverpoint[flask]"   # or [django]
# or
uv add silverpoint
Tip
Building a Reflex app? Use reflex-silverpoint-react: it wraps the React components themselves, with the UI components and the dashboard. silverpoint is for everything else in Python: notebooks, Flask, Django, scripts and static HTML.

A chart

A builder takes the data and one keyword per role (a column name) and per option, and returns a Chart. Its spec is the chart spec @silverpoint/embed draws, built and validated when the chart is made.

python
import pandas as pd
import silverpoint

df = pd.DataFrame({"team": ["A", "B", "C"], "wins": [12, 9, 15]})
chart = silverpoint.bar_chart(df, x="team", value="wins", orientation="rows", title="Wins")

chart.spec        # the ChartSpec, a dict
chart.to_html()   # a complete, self-contained page (the script inlined; no network)
chart.to_svg()    # the library's renderToSVG bytes (needs Node 20+ on PATH)
python
{'chart': 'bar-chart',
 'data': [{'team': 'A', 'wins': 12}, {'team': 'B', 'wins': 9}, {'team': 'C', 'wins': 15}],
 'props': {'orientation': 'rows', 'title': 'Wins', 'xKey': 'team', 'valueKey': 'wins'}}

Chart(slug, data, roles=…, options=…) is the same thing by name. Both take the appearance (ground, substrate, mode, palette), width, height and id. The common props are snake_case keywords (data_table, footer_left, hatch_fill…); the common value prop (the figure in the card's header) is value_, since value names a role.

python
# the same chart, by slug: roles are the columns, options the chart's props
chart = silverpoint.Chart(
    "bar-chart",
    df,
    roles={"x": "team", "value": "wins"},
    options={"orientation": "rows", "title": "Wins"},
    ground="silverpoint", substrate="green", mode="precision", palette="verdigris",
    width=480,
)

silverpoint.catalog["version"]   # the host catalog the builders are generated from
silverpoint.SILVERPOINT_VERSION   # the @silverpoint/embed version vendored

The builders

One builder per chart a table can feed: 56 of the 60, generated from the host catalog with full type hints (an editor completes each chart's roles and the values of its options). Four charts take no table (orbit, sparkline rows, volvelle and the grid treemap). 9 families: areas (3), bars (8), distributions-comparisons (14), fields-networks (5), flows (2), hierarchies-dimensions (8), lines (3), points-grids (4), radial (9). Roles in brackets are optional.

BuilderChartRoles
activity_grid()Activity griddate [count] [level]
area_chart()Area chartx value
bar_chart()Bar chartx value [secondary]
beeswarm_chart()Beeswarm chartvalue [group] [label]
box_plot_chart()Box plot chartvalue [group]
bubble_chart()Bubble chartx y size
bullet_chart()Bullet charttitle actual target
bump_chart()Bump chartx series value
candlestick_chart()Candlestick charttime open high low close
chord_ring()Chord ringsource target value
composed_chart()Composed chartx bar [line]
connected_scatter_chart()Connected scatter chartx y [label]
contour_chart()Contour chartx y [value]
coxcomb_chart()Coxcomb chartname value
delaunay_chart()Delaunay chartx y [label]
density_bin_chart()Density bin chartx y
diverging_bar_chart()Diverging bar chartlabel levels
donut_chart()Donut chartname value
dumbbell_chart()Dumbbell chartlabel start end
ecdf_chart()ECDF chartvalue [group]
error_bar_chart()Error bar chartlabel estimate low high
funnel_chart()Funnel chartstage value
gauge_arc()Gauge arcpercent
heatmap_chart()Heatmap chartrow column value
histogram_chart()Histogram chartvalue
interval_chart()Interval chartlane start end [label]
kpi_card()KPI cardvalue
line_chart()Line chartx value [secondary]
lollipop_chart()Lollipop chartx value
marimekko_chart()Marimekko chartcolumn segment value
meter_chart()Meter chartpercent
network_chart()Network chartsource target [value]
parallel_coordinates_chart()Parallel coordinates chart[label] dimensions
polar_bar_chart()Polar bar chartname value
polar_line_chart()Polar line chartangle value
polar_scatter_chart()Polar scatter chartangle radius [size]
pyramid_chart()Pyramid chartlabel width [tone]
radar_chart()Radar chartsubject value
radial_arc_group()Radial arc groupname value
radial_rings()Radial ringsname value
range_band_chart()Range band chartx low high
ridgeline_chart()Ridgeline chartvalue group
sankey_chart()Sankey chartsource target value
scatter_chart()Scatter chartx y [size]
slope_chart()Slope chartlabel start end
squarified_treemap()Squarified treemapid parent [label] value
stacked_bar_chart()Stacked bar chartx values
step_chart()Step chartx value
stream_chart()Stream chartx values
sunburst_chart()Sunburst chartid parent [label] value
tree_chart()Tree chartid parent [label] [value]
vector_field_chart()Vector field chartx y u v
violin_chart()Violin chartvalue [group]
waffle_chart()Waffle chartname value
waterfall_chart()Waterfall chartstep [base] [delta]
wind_rose()Wind rosebearing value

Data in

Rows, a mapping of columns, a pandas or polars DataFrame, a pyarrow Table, and in Databricks a Spark or pandas-on-Spark DataFrame or the Rows of collect(). Charts drawn from a matrix, such as the heatmap, take the long table and the package reshapes it: row, column and value are three columns.

python
import polars as pl
import pyarrow as pa

rows = [{"team": "A", "wins": 12}, {"team": "B", "wins": 9}]   # a list of rows
columns = {"team": ["A", "B"], "wins": [12, 9]}                 # a mapping of columns

silverpoint.bar_chart(rows, x="team", value="wins")
silverpoint.bar_chart(columns, x="team", value="wins")
silverpoint.bar_chart(pl.DataFrame(columns), x="team", value="wins")
silverpoint.bar_chart(pa.table(columns), x="team", value="wins")
# dates become ISO strings; NaN and NaT become None

Errors before HTML

A role, column, option or value the catalog does not know raises SpecError naming the closest valid names, when the chart is made: no page is written with a chart that cannot draw.

python
from silverpoint import SpecError

try:
    silverpoint.bar_chart(df, x="teem", value="wins")
except SpecError as error:
    print(error.kind, error)
# role the data has no column "teem" Did you mean "team"?. Columns: "team", "wins".

silverpoint.bar_chart(df, x="team", value="wins", orientation="sideways")
# SpecError: bar-chart: "sideways" is not a value of `orientation`; its values are "columns", "rows".

silverpoint.Chart("bar-chrt")
# SpecError: Unknown chart "bar-chrt". Did you mean "bar-chart"?
RaisedWhen
SpecErrorA chart, role, column, option or value the pinned catalog does not know, before any HTML is written; error.kind is chart, role, prop, shape or value.
RuntimeUnavailableto_svg() or render="server" with no Node 20+ on PATH.
ValueErrorA Spark DataFrame over SPARK_ROW_LIMIT (10,000) rows: aggregate in Spark first.

Jupyter, JupyterLab, VS Code

A chart as a cell's value draws itself: each one is a sandboxed <iframe srcdoc> holding the inline page, so it needs no trusted notebook and keeps its stylesheet off the notebook's. silverpoint.notebook.enable() shows the script once and writes later charts as <silverpoint-chart> elements, for front ends that run scripts in outputs. quickstart.ipynb.

python
import pandas as pd
import silverpoint

df = pd.DataFrame({"hour": ["00", "04", "08", "12", "16", "20"], "hits": [18, 11, 34, 71, 74, 62]})
silverpoint.line_chart(df, x="hour", value="hits", title="Hits per hour", curve="monotone")
# the chart is the cell's value: it draws itself in a sandboxed <iframe srcdoc>

# front ends that run scripts in outputs can share one copy of the script:
silverpoint.notebook.enable()    # shows the script once; later charts are <silverpoint-chart>
silverpoint.notebook.disable()   # back to one frame per chart

Databricks

A Spark DataFrame goes straight into a builder, and a chart as a cell's value draws itself. displayHTML(chart.to_html(render="client")) draws a chart anywhere in a cell, so one cell can draw several. databricks.py is a notebook to import (Databricks source format) that runs on samples.nyctaxi.trips.

python
# %pip install silverpoint
from pyspark.sql import functions as F
import silverpoint

trips = spark.read.table("samples.nyctaxi.trips")
by_hour = (
    trips.groupBy(F.hour("tpep_pickup_datetime").alias("hour"))
    .agg(F.count("*").alias("trips"), F.round(F.avg("fare_amount"), 2).alias("fare"))
    .orderBy("hour")
    .withColumn("hour", F.format_string("%02d:00", "hour"))
)

# a Spark DataFrame goes straight into a builder; the chart draws itself as the cell's value
silverpoint.line_chart(by_hour, x="hour", value="trips", secondary="fare", title="Trips per pickup hour")

# several charts in one cell: displayHTML draws each where it is called
displayHTML(silverpoint.bar_chart(by_hour, x="hour", value="trips").to_html(render="client"))
  • Rows. At most silverpoint.data.SPARK_ROW_LIMIT (10,000) rows are read, through limit, so a large table never reaches the driver; a bigger DataFrame raises ValueError. Aggregate in Spark first.
  • Size. Each chart carries its own copy of the script (about 0.5 MB; 1.1 MB with 10,000 rows). A cell's output may be 10 MB by default on Runtime 17+, and a notebook keeps about fifteen charts before Databricks stops saving its revision snapshots.
  • silverpoint.notebook.enable() has no effect there and warns: each output is its own frame.

Flask

Silverpoint(app) (or Silverpoint().init_app(app)) serves the vendored script at /_silverpoint/, immutable for a year, and adds two Jinja globals: silverpoint_script() and silverpoint_chart(chart), which also takes a spec.

python
from flask import Flask, render_template_string
import silverpoint
from silverpoint.contrib.flask import Silverpoint

app = Flask(__name__)
Silverpoint(app)  # serves the script at /_silverpoint/, immutable, and adds two Jinja globals

PAGE = """<!doctype html>
<html lang="en"><head><meta charset="utf-8"><title>Wins</title>{{ silverpoint_script() }}</head>
<body><h1>Wins per team</h1>{{ silverpoint_chart(chart) }}</body></html>"""


@app.after_request
def csp(response):
    response.headers["Content-Security-Policy"] = "script-src 'self'; style-src 'self'"
    return response


@app.route("/")
def index():
    rows = [{"team": "A", "wins": 12}, {"team": "B", "wins": 9}, {"team": "C", "wins": 15}]
    chart = silverpoint.bar_chart(rows, x="team", value="wins", title="Wins", orientation="rows")
    return render_template_string(PAGE, chart=chart)
Note
The Flask and Django markup has no inline script or style: it renders under Content-Security-Policy: script-src 'self'; style-src 'self', as the examples set.

Django

Add "silverpoint.contrib.django" to INSTALLED_APPS (with django.contrib.staticfiles): the script is a static file, so collectstatic ships it, and two template tags write the markup.

python
# settings.py
INSTALLED_APPS = [
    "django.contrib.staticfiles",
    "silverpoint.contrib.django",   # the template tags and the script as a static file
    # …
]
python
# views.py
from django.shortcuts import render
import silverpoint


def index(request):
    rows = [{"team": "A", "wins": 12}, {"team": "B", "wins": 9}, {"team": "C", "wins": 15}]
    chart = silverpoint.bar_chart(rows, x="team", value="wins", title="Wins", orientation="rows")
    return render(request, "index.html", {"chart": chart})
html
{% load silverpoint %}<!doctype html>
<html lang="en"><head><meta charset="utf-8"><title>Wins</title>{% silverpoint_script %}</head>
<body><h1>Wins per team</h1>{% silverpoint_chart chart %}</body></html>

Static HTML and SVG

to_html() writes a page that opens from disk, a report or an e-mail attachment; to_svg() returns the library's renderToSVG output (embed_fonts=True inlines EB Garamond) and, like render="server", needs Node 20+ on PATH. A CDN URL is never written.

python
from pathlib import Path

# a self-contained page: the vendored script inlined, no network, opens from disk
Path("wins.html").write_text(chart.to_html())

# a fragment for a page that loads the script itself
box = chart.to_html(full_document=False, render="client")
# <div data-sp-embed><script type="application/json">{"chart":"bar-chart",…}</script></div>

# a page whose script your application serves (never a CDN), pinned by its integrity
page = chart.to_html(script="/static/silverpoint-embed.full.js", integrity="sha384-…")

silverpoint.static_path()   # the folder holding silverpoint-embed.full.js, for any framework
KeywordDefault
full_documentTrueA whole page, or only the chart's markup.
script"inline""inline" (the vendored file in the page), "none" (the page loads it) or a URL your application serves.
render"auto""server" draws in Node with the library's renderToHTML (byte-identical; the script then adopts it); "client" writes only the spec and the script draws it; "auto" is server when Node is on PATH.
title / langthe chart's name / "en"The page's <title> and lang.
integrityNoneThe script's SHA-384, with a script URL.

Specs from elsewhere

Chart.from_spec takes a spec already written: the JSON of @silverpoint/embed, or what the MCP server's generate_code returns. Use with AI →

python
# a spec written elsewhere, for instance by the MCP server's generate_code
chart = silverpoint.Chart.from_spec({
    "chart": "donut-chart",
    "data": [{"name": "Rent", "value": 38}, {"name": "Food", "value": 22}],
    "props": {"nameKey": "name", "valueKey": "value", "title": "Budget"},
})
chart.to_html()

Source, the Flask, Django and notebook examples, and issues: ecrespo/silverpoint-python. On PyPI: silverpoint 0.11.0.