Skip to main content

datasette-init

PyPI Changelog License

Ensure specific tables and views exist on startup

Installation

Install this plugin in the same environment as Datasette.

$ pip install datasette-init

Usage

This plugin is configured using metadata.json (or metadata.yaml).

Creating tables

Add a block like this that specifies the tables you would like to ensure exist:

{
  "plugins": {
    "datasette-init": {
      "my_database": {
        "tables": {
          "dogs": {
            "columns": {
              "id": "integer",
              "name": "text",
              "age": "integer",
              "weight": "float"
            },
            "pk": "id"
          }
        }
      }
    }
  }
}

Any tables that do not yet exist will be created when Datasette first starts.

Valid column types are "integer", "text", "float" and "blob".

The "pk" is optional, and is used to define the primary key. To define a compound primary key (across more than one column) use a list of column names here:

    "pk": ["id1", "id2"]

Creating views

The plugin can also be used to create views:

{
  "plugins": {
    "datasette-init": {
      "my_database": {
        "views": {
          "my_view": "select 1 + 1"
        }
      }
    }
  }
}

Each view in the "views" block will be created when the Database first starts. If a view with the same name already exists it will be replaced with the new definition.

Development

To set up this plugin locally, first checkout the code. Then create a new virtual environment:

cd datasette-init
python3 -mvenv venv
source venv/bin/activate

Or if you are using pipenv:

pipenv shell

Now install the dependencies and tests:

pip install -e '.[test]'

To run the tests:

pytest

Metadata

Release files for datasette-init 0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for datasette-init 0.2
File Size Uploaded
datasette-init-0.2.tar.gz 2.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for datasette-init 0.2
File Interpreter ABI Platform
datasette_init-0.2-py3-none-any.whl Python 3 none any Details

Total release size: 5.8 kB

Release files / datasette-init-0.2.tar.gz

Download URL datasette-init-0.2.tar.gz
Size 2.9 kB
Tags Source
SHA-256 checksum
How to use checksums
6b92a3cb396fbf777d2891d385da6238e9c7c4b7a1cf02c7966d2206123be398
BLAKE2b-256 checksum
How to use checksums
0ba935870161d1db6c303cc5f7b060ea92c3f3401b194bd5f7458e46c6afd331
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

Release files / datasette_init-0.2-py3-none-any.whl

Download URL datasette_init-0.2-py3-none-any.whl
Size 2.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
230b5570f247d5483a93cacf1f220a7b45d336a564dc6e6e60afc3a5957040b7
BLAKE2b-256 checksum
How to use checksums
4f764b3651e82457182ec21bd55ea18bdca9fa3b85d3c3b1e0075df14100e3ff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

Release history Release notifications | RSS feed

This release

0.2 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page