datasette-lite
datasette-lite copied to clipboard
Datasette running in your browser using WebAssembly and Pyodide
Datasette Lite
Datasette running in your browser using WebAssembly and Pyodide
Live tool: https://lite.datasette.io/
More about this project:
- Datasette Lite: a server-side Python web application running in a browser
- Joining CSV files in your browser using Datasette Lite
How this works
Datasette Lite runs the full server-side Datasette Python web application directly in your browser, using the Pyodide build of Python compiled to WebAssembly.
When you launch the demo, your browser will download and start executing a full Python interpreter, install the datasette package (and its dependencies), download one or more SQLite database files and start the application running in a browser window (actually a Web Worker attached to that window).
Loading CSV data
You can load data from a CSV file hosted online (provided it allows access-control-allow-origin: *
) by passing that URL as a ?csv=
parameter - or by clicking the "Load CSV by URL" button and pasting in a URL.
This example loads a CSV of college fight songs from the fivethirtyeight/data GitHub repository:
- https://lite.datasette.io/?csv=https%3A%2F%2Fraw.githubusercontent.com%2Ffivethirtyeight%2Fdata%2Fmaster%2Ffight-songs%2Ffight-songs.csv
You can pass ?csv=
multiple times to load more than one CSV file. You can then execute SQL joins to combine that data.
This example loads the latest Covid-19 per-county data from the NY Times, the 2019 county populations data from the US Census, joins them on FIPS code and runs a query that calculates cases per million across that data:
Loading SQLite databases
You can use this tool to open any SQLite database file that is hosted online and served with a access-control-allow-origin: *
CORS header. Files served by GitHub Pages automatically include this header, as do database files that have been published online using datasette publish.
Copy the URL to the .db
file and either paste it into the "Load SQLite DB by URL" prompt, or construct a URL like the following:
https://lite.datasette.io/?url=https://latest.datasette.io/fixtures.db
Some examples to try out:
- Global Power Plants - 33,000 power plants around the world
- United States members of congress - the example database from the Learn SQL with Datasette tutorial
Initializing with SQL
You can also initialize the data.db
database by passing the URL to a SQL file. The easiest way to do this is to create a GitHub Gist.
This example SQL file creates a table and populates it with three records. It's hosted in this Gist.
https://gist.githubusercontent.com/simonw/ac4e19920b4b360752ac0f3ce85ba238/raw/90d31cf93bf1d97bb496de78559798f849b17e85/demo.sql
You can paste this URL into the "Load SQL by URL" prompt, or you can pass it as the ?sql=
parameter like this.
SQL will be executed before any CSV imports, so you can use initial SQL to create a table and then use ?csv=
to import data into it.
Installing plugins
Datasette has a number of plugins that enable new features.
You can install plugins into Datasette Lite by adding one or more ?install=name-of-plugin
parameters to the URL.
Not all plugins are compatible with Datasette Lite at the moment, for example plugins that load their own JavaScript and CSS do not currently work, see issue #8.
Here's a list of plugins that have been tested with Datasette Lite, plus demo links to see them in action:
- datasette-packages - Show a list of currently installed Python packages - demo
- datasette-dateutil - dateutil functions for Datasette - demo
- datasette-schema-versions - Datasette plugin that shows the schema version of every attached database - demo
- datasette-debug-asgi - Datasette plugin for dumping out the ASGI scope. - demo
- datasette-query-links - Turn SELECT queries returned by a query into links to execute them - demo
- datasette-json-html - Datasette plugin for rendering HTML based on JSON values - demo
- datasette-haversine - Datasette plugin that adds a custom SQL function for haversine distances - demo
- datasette-jellyfish - Datasette plugin that adds custom SQL functions for fuzzy string matching, built on top of the Jellyfish Python library - demo
- datasette-pretty-json - Datasette plugin that pretty-prints any column values that are valid JSON objects or arrays. - demo
- datasette-yaml - Export Datasette records as YAML - demo
- datasette-copyable - Datasette plugin for outputting tables in formats suitable for copy and paste - demo