dj-plotly-codecs
DataJoint codecs for storing Plotly figures as JSON files with schema-addressed paths.
Overview
This package provides a DataJoint codec that stores Plotly figures as standard
Plotly JSON files in object storage, using DataJoint's schema-addressed storage
system. The stored file is the one Figure.write_json writes: Plotly reads it
back with plotly.io.read_json, and any page that loads Plotly's JavaScript
renders it with Plotly.newPlot. The .plotly.json file name and the codec
type tell tools that a column holds figures, not arbitrary JSON.
Features
- Renderable files: every stored figure is a standard Plotly JSON file
- Validated: with plotly installed, a figure is validated on insert
- Lazy loading: the number of traces, their types, the title, and the file size are known without downloading the file
- Plotly optional: dict figures are stored without plotly installed; plotly
adds validation and
Figureobjects on fetch - Schema-addressed storage: paths mirror the database structure
(
{schema}/{table}/{pk}/{field}_{token}.plotly.json) - Automatic registration: the codec is available after installation
Installation
pip install "dj-plotly-codecs[plotly]"
Requires Python 3.10 or later and datajoint>=2.3.4.
Without the plotly extra, the codec stores and loads dict figures, without
validation and without Figure objects.
Quick Start
import datajoint as dj
import plotly.graph_objects as go
schema = dj.Schema("my_schema")
@schema
class TuningPlot(dj.Manual):
definition = """
cell_id : int32
---
figure : <plotly@> # a figure any Plotly viewer renders
"""
fig = go.Figure(go.Scatter(x=[0, 45, 90, 135], y=[2.1, 5.3, 1.8, 0.9]))
fig.update_layout(title="Orientation tuning")
TuningPlot.insert1({"cell_id": 1, "figure": fig})
# Fetch returns a lazy reference
ref = (TuningPlot & {"cell_id": 1}).fetch1("figure")
print(ref.traces, ref.trace_types, ref.title) # 1 ['scatter'] Orientation tuning
ref.to_figure().show() # downloads the file; a plotly Figure
figure = ref.load() # the figure as a dict
Configuration
Configure your object storage in DataJoint:
dj.config["stores"] = {
"mystore": {
"protocol": "s3",
"endpoint": "s3.amazonaws.com",
"bucket": "my-bucket",
"location": "datajoint",
}
}
Codecs
<plotly@> / <plotly@store>
Store Plotly figures as .plotly.json files with schema-addressed paths.
Accepted values:
| value | stored as |
|---|---|
plotly.graph_objects.Figure |
plotly.io.to_json(figure) |
dict with data, layout, frames |
validated by plotly when it is installed |
A dict figure has a data list of traces and optional layout and frames, as
Figure.to_plotly_json() returns. Anything else is refused rather than stored,
and so is a figure plotly finds invalid. With plotly installed, the file is
exactly what Figure.write_json writes; plotly 6 and later write numpy arrays
as base64 typed arrays, which Plotly.js 2.28 and later render. Without plotly
installed, a dict figure is written as plain JSON: numpy arrays as lists, NaN
and infinity as null, dates and times as ISO 8601 strings.
On fetch, a PlotlyRef:
| member | needs the file |
|---|---|
traces, trace_types, title, size |
no |
load(): the figure as a dict |
yes |
to_figure(): a plotly Figure |
yes (and plotly) |
Usage:
class MyTable(dj.Manual):
definition = """
id : int32
---
figure : <plotly@> # Default store
summary : <plotly@s3> # Specific store
"""
Development
Setup
git clone https://github.com/datajoint/dj-plotly-codecs.git
cd dj-plotly-codecs
pip install -e ".[plotly]"
Testing
pytest
The database tests start MySQL in Docker through testcontainers and are skipped when Docker is not available.
Code Style
This project uses Ruff for linting and formatting:
ruff check src tests
ruff format src tests
Contributing
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
License
Apache License 2.0. Copyright 2026 DataJoint Inc. See LICENSE for details.
Related Projects
- DataJoint - Framework for scientific data pipelines
- dj-png-codecs - DataJoint codecs for images as PNG files
- dj-zarr-codecs - DataJoint codecs for Zarr arrays
- datajoint-python - DataJoint for Python
Documentation & Support
- DataJoint Documentation - Complete DataJoint documentation
- GitHub Issues - Report bugs and request features
Metadata
Release files for dj-plotly-codecs 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| dj_plotly_codecs-0.1.0.tar.gz | 166.4 kB | With provenance | Details for dj_plotly_codecs-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dj_plotly_codecs-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for dj_plotly_codecs-0.1.0-py3-none-any.whl |
Total release size: 179.4 kB
Release files / dj_plotly_codecs-0.1.0.tar.gz
| Download URL | dj_plotly_codecs-0.1.0.tar.gz |
|---|---|
| Size | 166.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d14ec08c3ef6159fa2bb53a729720ec31237991abd55326911b4c22c7f2f4ec2
|
|
BLAKE2b-256 checksum How to use checksums |
b52f5452f3d70ef32297e048ee49deb5e0f7eb442601082252d282ee53813cc0
|
| 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 30, 2026.
Transparency logRelease files / dj_plotly_codecs-0.1.0-py3-none-any.whl
| Download URL | dj_plotly_codecs-0.1.0-py3-none-any.whl |
|---|---|
| Size | 13.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1e39012541e0eefb931a1884fc98bc07b409efddcce71900157e15fd4d38c600
|
|
BLAKE2b-256 checksum How to use checksums |
30e09f6aead057139e955919d9288a0ced4e27bf070b451a2f1984872ae9635b
|
| 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 30, 2026.
Transparency logSecurity for dj-plotly-codecs 0.1.0
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.
Attestation for dj_plotly_codecs-0.1.0.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 30, 2026.
Transparency logA 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.