Package: datasette-app-support
datasette-app-supportPart ofhttps://github.com/simonw/datasette-appInstallationInstall this plugin in the same environment as Datasette.$ datasette install datasette-app-supportUsing this outside of the context ofDatasette.appprobably won't work.API endpointsThis plugin exposes APIs that are called by the Electron wrapper.All plugins are protected by authentication: they need to be called with aAuthorization: Bearer xxxtoken here thexxxmatches the value of theDATASETTE_API_TOKENenvironment variable./-/auth-app-userPOST /-/auth-app-user
{"redirect": "/-/metadata"}If a validAuthorizationheader is passed, sets a signed cookie identifying the user as{"id": "admin"}and redirects them to the specified page./-/open-database-filePOST /-/open-database-file
{"path": "/path/to/file.db"}Attaches a new database file to the running Datasette instance - used by the "Open Database..." menu option.Returns HTTP 200 status with{"ok": True, "path": "/file"}if it works, 400 with an"error"JSON string message if it fails./-/new-empty-database-filePOST /-/new-empty-database-file
{"path": "/path/to/file.db"}Creates a brand new empty SQLite database file at the specified path and attaches it to the Datasette instance. Used by the "Create Empty Database..." menu option.Returns HTTP 200 status with{"ok": True, "path": "/file"}if it works, 400 with an"error"JSON string message if it fails./-/open-csv-filePOST /-/open-csv-file
{"path": "/path/to/file.csv"}Imports a CSV or TSV file into the default/temporaryin-memory database. Used by the "Open CSV..." menu option.Returns HTTP 200 status with{"ok": True, "path": "/temporary/table"}if it works, 400 or 500 with an"error"JSON string message if it fails./-/import-csv-filePOST /-/import-csv-file
{"path": "/path/to/file.csv", "database": "database_name"}Permanently imports a CSV or TSV file into the specified database. Used by the "Import CSV..." menu option.Returns HTTP 200 status with{"ok": True, "path": "/database_name/table"}if it works, 400 or 500 with an"error"JSON string message if it fails./-/open-csv-from-urlPOST /-/open-csv-from-url
{"url": "https://example.com/file.csv", "table_name": "My_suggested_table_name"}Imports a CSV file into the default/temporaryin-memory database. Used by the "Open CSV from URL..." menu option.table_nameis optional - if omitted the name to use will be derived from the URL.Returns HTTP 200 status with{"ok": True, "path": "/temporary/table"}if it works, 400 or 500 with an"error"JSON string message if it fails./-/dump-temporary-to-filePOST /-/dump-temporary-to-file
{"path": "/path/to/backup.db"}Dumps the contents of thetemporaryin-memory database to the specified file. This is intended to be used to take a temporary backup when the Datasette server is restarted after a plugin has been installed, seedatasette-app/issues/42.Returns HTTP 200 status with{"ok": True, "path": "/path/to/backup.db"}if it works, 400 or 500 with an"error"JSON string message if it fails./-/restore-temporary-to-filePOST /-/restore-temporary-from-file
{"path": "/path/to/backup.db"}Restores thetemporaryin-memory database to the contents of the specified file.Returns HTTP 200 status with{"ok": True, "path": "/path/to/backup.db"}if it works, 400 or 500 with an"error"JSON string message if it fails.DevelopmentTo set up this plugin locally, first checkout the code. Then create a new virtual environment:cd datasette-app-support
python3 -mvenv venv
source venv/bin/activateOr if you are usingpipenv:pipenv shellNow install the dependencies and test dependencies:pip install -e '.[test]'To run the tests:pytest