New in 0.11
Python: notebooks, Flask, Django
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.
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.
pip install silverpoint # no dependencies
pip install "silverpoint[flask]" # or [django]
# or
uv add silverpointsilverpoint 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.
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){'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.
# 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 vendoredThe 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.
| Builder | Chart | Roles |
|---|---|---|
activity_grid() | Activity grid | date [count] [level] |
area_chart() | Area chart | x value |
bar_chart() | Bar chart | x value [secondary] |
beeswarm_chart() | Beeswarm chart | value [group] [label] |
box_plot_chart() | Box plot chart | value [group] |
bubble_chart() | Bubble chart | x y size |
bullet_chart() | Bullet chart | title actual target |
bump_chart() | Bump chart | x series value |
candlestick_chart() | Candlestick chart | time open high low close |
chord_ring() | Chord ring | source target value |
composed_chart() | Composed chart | x bar [line] |
connected_scatter_chart() | Connected scatter chart | x y [label] |
contour_chart() | Contour chart | x y [value] |
coxcomb_chart() | Coxcomb chart | name value |
delaunay_chart() | Delaunay chart | x y [label] |
density_bin_chart() | Density bin chart | x y |
diverging_bar_chart() | Diverging bar chart | label levels |
donut_chart() | Donut chart | name value |
dumbbell_chart() | Dumbbell chart | label start end |
ecdf_chart() | ECDF chart | value [group] |
error_bar_chart() | Error bar chart | label estimate low high |
funnel_chart() | Funnel chart | stage value |
gauge_arc() | Gauge arc | percent |
heatmap_chart() | Heatmap chart | row column value |
histogram_chart() | Histogram chart | value |
interval_chart() | Interval chart | lane start end [label] |
kpi_card() | KPI card | value |
line_chart() | Line chart | x value [secondary] |
lollipop_chart() | Lollipop chart | x value |
marimekko_chart() | Marimekko chart | column segment value |
meter_chart() | Meter chart | percent |
network_chart() | Network chart | source target [value] |
parallel_coordinates_chart() | Parallel coordinates chart | [label] dimensions |
polar_bar_chart() | Polar bar chart | name value |
polar_line_chart() | Polar line chart | angle value |
polar_scatter_chart() | Polar scatter chart | angle radius [size] |
pyramid_chart() | Pyramid chart | label width [tone] |
radar_chart() | Radar chart | subject value |
radial_arc_group() | Radial arc group | name value |
radial_rings() | Radial rings | name value |
range_band_chart() | Range band chart | x low high |
ridgeline_chart() | Ridgeline chart | value group |
sankey_chart() | Sankey chart | source target value |
scatter_chart() | Scatter chart | x y [size] |
slope_chart() | Slope chart | label start end |
squarified_treemap() | Squarified treemap | id parent [label] value |
stacked_bar_chart() | Stacked bar chart | x values |
step_chart() | Step chart | x value |
stream_chart() | Stream chart | x values |
sunburst_chart() | Sunburst chart | id parent [label] value |
tree_chart() | Tree chart | id parent [label] [value] |
vector_field_chart() | Vector field chart | x y u v |
violin_chart() | Violin chart | value [group] |
waffle_chart() | Waffle chart | name value |
waterfall_chart() | Waterfall chart | step [base] [delta] |
wind_rose() | Wind rose | bearing 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.
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 NoneErrors 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.
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"?| Raised | When |
|---|---|
SpecError | A 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. |
RuntimeUnavailable | to_svg() or render="server" with no Node 20+ on PATH. |
ValueError | A 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.
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 chartDatabricks
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.
# %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, throughlimit, so a large table never reaches the driver; a bigger DataFrame raisesValueError. 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.
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)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.
# settings.py
INSTALLED_APPS = [
"django.contrib.staticfiles",
"silverpoint.contrib.django", # the template tags and the script as a static file
# …
]# 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}){% 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.
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| Keyword | Default | |
|---|---|---|
full_document | True | A 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 / lang | the chart's name / "en" | The page's <title> and lang. |
integrity | None | The 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 →
# 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.