Datasette
To run the Datasette data exploration tool using Unit:
-
Install Unit with a Python 3.6+ language module.
-
Create a virtual environment to install Datasette’s PIP package, for instance:
$ cd /path/to/app/ # Path to the application directory; use a real path in your configuration $ python --version # Make sure your virtual environment version matches the module version Python X.Y.Z # Major version, minor version, and revision number $ python -m venv venv # Arbitrary name of the virtual environment $ source venv/bin/activate # Name of the virtual environment from the previous command $ pip install datasette $ deactivate
-
Running Datasette on Unit requires a wrapper to expose the application object as the ASGI callable. Let’s use the following basic version, saving it as /path/to/app/asgi.py:
import glob from datasette.app import Datasette application = Datasette(glob.glob('*.db')).app()
-
Change ownership:
Run the following command (as root) so Unit can access the application directory (If the application uses several directories, run the command for each one):
# chown -R unit:unit /path/to/app/ # User and group that Unit's router runs as by default
The unit:unit user-group pair is available only with official packages , Docker images, and some third-party repos. Otherwise, account names may differ; run theps aux | grep unitd
command to be sure.For further details, including permissions, see the security checklist.
-
Next, prepare the Datasette configuration for Unit (use real values for type, home, and path):
{ "listeners": { "*:80": { "pass": "applications/datasette" } }, "applications": { "datasette": { "type": "python 3.Y", "_comment_type": "Must match language module version and virtual environment version", "path": "/path/to/app/", "_comment_path": "Path to the ASGI module", "home": "/path/to/app/venv/", "_comment_home": "Path to the virtual environment, if any", "module": "asgi", "_comment_module": "ASGI module filename with extension omitted", "callable": "app", "_comment_callable": "Name of the callable in the module to run" } } }
-
Upload the updated configuration.
Assuming the JSON above was added to
config.json
. Run the following command as root:# curl -X PUT --data-binary @config.json --unix-socket \ /path/to/control.unit.sock \ # Path to Unit's control socket in your installation http://localhost/config/ # Path to the config section in Unit's control API
After a successful update, Datasette should be available on the listener’s IP address and port: