plotlyshare is a small Python package that adds a custom plotly renderer (renderer='plotlyshare') so fig.show() uploads the interactive plot to the PlotlyShare web app (https://plotlyshare.pages.dev) and returns a shareable link. The whole library is 3 files in plotlyshare/. Development happens on the v2 branch (main holds the legacy v1 code).
Package management and builds use uv (not pip directly):
uv build -o dist/$(uv version --short) # build (see `task build` below)
task build # checks dist/<version> doesn't exist + version is free on TestPyPI, then builds
task upload-test # publish to TestPyPI (index configured in pyproject.toml)
task upload # publish to PyPITaskfile.yml(taskfile.dev) is the current build entrypoint; themakefileis the legacy v1 equivalent (usespy -m build/twine) — don't update it unless asked.- Releases require bumping
versioninpyproject.tomlfirst.task buildfails ifdist/<version>exists or the version already exists on TestPyPI. - TestPyPI is declared as an
explicit = trueuv index inpyproject.toml;task upload-testtargets it via--index testpypi. - There is no test suite, linter, or CI configured. The
testCLI subcommand (below) tests the user's credentials, not the code.
Defined in plotlyshare/__main__.py: setup, test, config, show_config.
setupprompts for aCLI_TOKEN(formatUID//TOKEN), tests the connection, and writes config.configprints the config and opens it in$EDITORif set.__main__.pyhard-asserts exactly one argument from the allowed list — adding a subcommand means updatingallowed_commands.
- Importing
plotlyshare(plotlyshare/__init__.py) reads~/.config/plotlyshare/config.json. If setup was done, it registers the renderer globally:pio.renderers['plotlyshare'] = PlotlyShareRenderer(config, {}). If not, it prints an error telling the user to run setup. Note: a bareimport plotlysharewith no valid config does nothing beyond that error message — the renderer registration is the import's entire side effect. fig.show(renderer='plotlyshare')callsPlotlyShareRenderer.render(fig)(plotlyshare/custom_plotly_renderer.py):- Serializes via
pio.to_json(orjson engine). optimize_template(default true at setup): if the figure'slayout.templatematches a built-in plotly template, replaces it with the template name to shrink the upload.- Generates a random two-word name (
wonderwords: adjective + noun) + ordinal date (e.g. "mushy pancake 24th Jul"), unlessplot_namewas passed tofig.show()(plotly forwards unknown kwargs to the renderer'srender; the renderer readsself.plot_nameand resets it toNoneafter each render). - POSTs to
{base_url}/api/upload?user={uid}with a BearerCLI_TOKENheader, prints the returned link/size viarich, optionally opens the browser.
- Serializes via
- Config location:
~/.config/plotlyshare/config.json(both__init__.pyand__main__.pybuild this path independently; keep them in sync). Keys:setup_done,UID,CLI_TOKEN,open_browser_after_upload,optimize_template. base_urloverride: the env varPLOTLYSHARE_BASE_URLoverrideshttps://plotlyshare.pages.dev— useful for local dev against a self-hosted frontend.- Windows emoji crash:
__main__.pyreconfigures stdout/stderr to UTF-8 because piped Windows stdout defaults to cp1252, which crashes on emoji output. Preserve this if touching CLI output code. - Lazy templates:
pio.templateslazy-loads, so you can't naively iterate.items()on it —render()usespio.templates.keys()+.to_plotly_json()comparison for that reason (noted in a comment). - Auth:
CLI_TOKENis sent asAuthorization: Bearer <token>; the UID goes in the query string (?user={uid}), both in upload and in the connection test (/api/auth/ping_cli). - Style: the codebase uses tabs for indentation,
richfor all user-facing CLI output (occasionally mixing plainprintfor format-control reasons, with an apologetic comment), and type hints only sporadically.
v2 (this branch) dropped the Google Drive/OAuth flow of v1 for the token-based backend. v1 artifacts still exist (makefile, plotlyshare.egg-info/, old dist/ versions); ignore them when working on v2.