NGINX Unit
v. 1.20.0

Datasette§

To run the Datasette data exploration tool using Unit:

  1. Install Unit with a Python 3.6+ language module.

  2. Create a virtual environment to install Datasette’s PIP package:

    $ cd /path/to/app/
    $ python3 -m venv venv
    $ source venv/bin/activate
    $ pip install datasette
    $ deactivate
    
  3. Running Datasette in 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()
    
  4. Set installation path permissions to secure access, for example:

    # chown -R app_user:app_group /path/to/app/
    

    Replace the placeholders above with actual values, noting them for later use in Unit configuration.

  5. Next, put together the Datasette configuration for Unit:

    {
        "listeners": {
            "*:80": {
                "pass": "applications/datasette"
            }
        },
    
        "applications": {
            "datasette": {
                "type": "python 3",
                "user": "app_user",
                "group": "app_group",
                "path": "/path/to/app/",
                "home": "/path/to/app/venv/",
                "module": "asgi",
                "callable": "app"
            }
        }
    }
    
  6. Upload the updated configuration. Assuming the JSON above was added to config.json:

    # curl -X PUT --data-binary @config.json --unix-socket \
           /path/to/control.unit.sock http://localhost/config/
    

    Note

    The control socket path may vary; run unitd --help or see Startup for details.

  7. After a successful update, Datasette should be available on the listener’s IP address and port:

    Datasette in Unit - Query Screen