simonw / datasette-jupyterlite

JupyterLite as a Datasette plugin
11 stars 0 forks source link

Utility functions for loading data from Datasette #2

Open simonw opened 2 years ago

simonw commented 2 years ago

Currently if you are inside JupyterLite and you want to load data from the host Datasette instance into a DataFrame or similar you need to do this:

from js import fetch
from io import StringIO
import pandas

df = pandas.read_csv(
  StringIO(await (await fetch("https://latest-with-plugins.datasette.io/github/stars.csv")).text())
)

It would be great if there was a less boilerplate heavy way of doing this.

JupyterLite
simonw commented 2 years ago

Better pattern for the above:

import pandas, pyodide
pandas.read_csv(pyodide.open_url(
  "https://latest-with-plugins.datasette.io/github/stars.csv")
)

Be nice if I didn't need the full URL and could instead just use /github/stars.csv.

Try it out at https://latest-with-plugins.datasette.io/jupyterlite/lab/index.html