Datasette plugin that scans directories for SQLite database files and serves them.
Install this plugin in the same environment as Datasette.
datasette install datasette-scanScan the current directory for SQLite files and serve them:
datasette scanScan a specific directory:
datasette scan /path/to/directoryScan multiple directories and include explicit database files:
datasette scan /data/projects /data/archives extra.dbSpecify a port (or any other datasette serve option):
datasette scan -p 8001All options accepted by datasette serve are also accepted by datasette scan -- these are introspected at runtime, so new options added to future versions of Datasette will be picked up automatically.
- Positional arguments that are directories are scanned recursively for SQLite files using the sqlite-scanner binary, which identifies SQLite files by their magic bytes rather than file extension.
- Positional arguments that are files are passed through directly as database files.
- If no positional arguments are given, the current directory (
.) is scanned. - Discovered files are then served as if you had run
datasette serve file1.db file2.db ....
Use --scan-interval to periodically re-scan directories for new SQLite files while the server is running. New databases will be added automatically.
datasette scan /data --scan-interval 5This re-scans every 5 seconds. Any new SQLite files that appear in the scanned directories will be added to the running Datasette instance without a restart.
Since datasette scan discovers files automatically, it takes precautions against problematic databases:
- Corrupted files are skipped. Each discovered file is validated by running
SELECT * FROM sqlite_masterbefore it is served. Files that fail this check are skipped with a warning to stderr. - Locked files are handled safely. Databases locked by another process are opened in read-only mode instead of causing the server to fail. (The
--nolockoption fromdatasette serveis always enabled and not exposed as a separate flag.)
These protections apply to files discovered by scanning directories. Explicit file arguments are passed through to datasette serve without validation.
Scan the current directory and open in a browser:
datasette scan -oScan with CORS enabled on a custom port:
datasette scan /data --cors -p 9000Use --get to test without starting a server:
datasette scan /data --get /.jsonTo set up this plugin locally, first checkout the code. You can confirm it is available like this:
cd datasette-scan
# Confirm the plugin is visible
uv run datasette pluginsTo run the tests:
uv run pytest