Lock fewer Python packages and install the rest at runtime

Open
#289 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
python, typescript, wasm

Research direction

Start by reading src/hooks/usePyodide.tsx and the package lock files build/shinylive/pyodide/pyodide-lock.json, shinylive_requirements.json, and shinylive_lock.json. Work out which packages must stay bundled for startup or compiled dependencies, then weigh runtime startup, offline exports, and version stability against reducing the lock. Done means a clear package selection and working lock and runtime install behavior; the issue leaves those trade-offs open.

Written by the indexing model from the issue text.

Description

dependencies enhancement

Problem

The shinylive assets pin every package an app might want. Updating any of them (for example shinychat) takes make update_packages_lock plus a new shinylive release, and then py-shinylive and Quarto have to pick up that release.

The bundled Pyodide's lock (build/shinylive/pyodide/pyodide-lock.json) lists 391 packages, about 303 MB:

  • Stock Pyodide packages, about 280 MB. numpy, pandas, scipy, matplotlib, ... from the Pyodide release archive. Most have compiled code, so they can't come from PyPI.
  • Packages shinylive adds, about 22 MB (shinylive_requirements.json → shinylive_lock.json):
    • built here: shiny, htmltools, shinywidgets, faicons, libsass;
    • from PyPI: shinychat, plotly, plotnine, altair, seaborn, ipywidgets, ipyleaflet, siuba, palmerpenguins, qrcode, shinyswatch, black, and their dependencies.

Runtime install already works: a package in an app's requirements.txt that is not in the lock is installed from PyPI by micropip at startup (_install_requirements_from_dir in src/hooks/usePyodide.tsx).

Idea

Lock less, and let micropip fetch the rest at runtime.

  • Keep in the lock: shiny and what it needs to start, the locally built wheels, and anything micropip can't install (compiled packages).
  • Consider dropping fast-moving or optional pure-Python packages (shinychat, plotly, plotnine, seaborn, ...) so apps get the latest version without a shinylive release.

Trade-offs to weigh

  • Apps that use an unlocked package need PyPI at runtime and start more slowly.
  • Versions are no longer the ones we tested, so a PyPI release can break apps and examples.
  • Exports and Quarto pages would no longer work offline for those packages, unless py-shinylive fetches them at export time.
  • Examples that use a dropped package need a requirements.txt entry.
  • Some PyPI packages need a newer compiled dependency than the bundled Pyodide has (for example, shinychat 0.7.x needs pydantic>=2.11, which Pyodide 0.27.7 didn't have).

Related

  • The website could also load the stock Pyodide packages from the Pyodide CDN instead of hosting them (about 280 MB less per deploy), as #288 does for the older shiny versions. That's a separate change from what is locked.
Dominant language
TypeScript
Stars
253
Forks
25
Avg merge
6d 22h
Merged PRs (30d)
13

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from posit-dev/shinylive

All issues in posit-dev/shinylive

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.