Skip to main content

Load example SQL scripts into Datasette on startup

Project description

datasette-examples

PyPI Changelog Tests License

Load example SQL scripts into Datasette on startup

Installation

Install this plugin in the same environment as Datasette.

pip install datasette-examples

Usage

This plugin is configured using metadata.yaml (or metadata.json or datasette.yml in Datasette 1.0).

Loading example SQL

Add a block like this that specifies the example SQL scripts you would like to load:

plugins:
  datasette-examples:
    startup:
      examples:
      - url: https://example.com/path/to/example1.sql
        if_not_table: table_name_1
      - url: https://example.com/path/to/example2.sql
        if_not_table: table_name_2

When Datasette starts running, it will:

  1. Check if the specified table (if_not_table) exists in the examples.db database
  2. If the table doesn't exist, it will download the SQL file from the provided URL
  3. Execute the SQL against examples.db

The if_not_table should be set to a table that is created by the script, to prevent the script from executing more than once.

Development

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

cd datasette-examples
python3 -m venv venv
source venv/bin/activate

Now install the dependencies and test dependencies:

pip install -e '.[test]'

To run the tests:

pytest

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

datasette_examples-0.1a0.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

datasette_examples-0.1a0-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file datasette_examples-0.1a0.tar.gz.

File metadata

  • Download URL: datasette_examples-0.1a0.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for datasette_examples-0.1a0.tar.gz
Algorithm Hash digest
SHA256 74f3528672675f36be8e016e21d1055912d52f3b9540365d2bd613a79cb06954
MD5 ee73ec736ab4c27469fdb62f61857b81
BLAKE2b-256 2b02682a2134b351a0991561e620325a69b969679db32c0eb8365eaf8c306702

See more details on using hashes here.

File details

Details for the file datasette_examples-0.1a0-py3-none-any.whl.

File metadata

File hashes

Hashes for datasette_examples-0.1a0-py3-none-any.whl
Algorithm Hash digest
SHA256 39f0a364a7aceec29c44daf4d06908ae45ab66d857676bfcfa013ac2e0625abb
MD5 f7f37161178a44290ae79d5d1cce7b38
BLAKE2b-256 a047090e7d4a2dc89407ea47b7ff79b3c073c0c76464a7dfc168ef8f0919564f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page