Part of https://github.com/simonw/datasette-app
Project description
datasette-app-support
Part of https://github.com/simonw/datasette-app
Installation
Install this plugin in the same environment as Datasette.
$ datasette install datasette-app-support
Using this outside of the context of Datasette.app
probably won't work.
API endpoints
This plugin exposes APIs that are called by the Electron wrapper.
All plugins are protected by authentication: they need to be called with a Authorization: Bearer xxx
token here the xxx
matches the value of the DATASETTE_API_TOKEN
environment variable.
/-/auth-app-user
POST /-/auth-app-user
{"redirect": "/-/metadata"}
If a valid Authorization
header is passed, sets a signed cookie identifying the user as {"id": "admin"}
and redirects them to the specified page.
/-/open-database-file
POST /-/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-file
POST /-/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-file
POST /-/open-csv-file
{"path": "/path/to/file.csv"}
Imports a CSV or TSV file into the default /temporary
in-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-file
POST /-/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-url
POST /-/open-csv-from-url
{"url": "https://example.com/file.csv", "table_name": "My_suggested_table_name"}
Imports a CSV file into the default /temporary
in-memory database. Used by the "Open CSV from URL..." menu option. table_name
is 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-file
POST /-/dump-temporary-to-file
{"path": "/path/to/backup.db"}
Dumps the contents of the temporary
in-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, see datasette-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-file
POST /-/restore-temporary-from-file
{"path": "/path/to/backup.db"}
Restores the temporary
in-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.
Development
To 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/activate
Or if you are using pipenv
:
pipenv shell
Now install the dependencies and test dependencies:
pip install -e '.[test]'
To run the tests:
pytest
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file datasette-app-support-0.11.8.tar.gz
.
File metadata
- Download URL: datasette-app-support-0.11.8.tar.gz
- Upload date:
- Size: 11.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b069f162bfea353d10b631d32ab180aeff33ebf0f0f43855905efd01a2b9276 |
|
MD5 | 51d1988d34f574affbf99b9a9a381085 |
|
BLAKE2b-256 | 945fe59dc0c028091828031176a1be3b1ed8863525b785ac20a933dbbd5d73cd |
File details
Details for the file datasette_app_support-0.11.8-py3-none-any.whl
.
File metadata
- Download URL: datasette_app_support-0.11.8-py3-none-any.whl
- Upload date:
- Size: 12.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ea20605c37bafe1f79b6c9d6a86faeed3b1db022c4ffefc425e4a48ac708282 |
|
MD5 | bc6a19e879a89f7971c424ccb260ad3e |
|
BLAKE2b-256 | 0c8cc6ef62182d743bd6ab0cbaf7cbd10bb236ef29dfd2d9037d92e68133a9d1 |