Skip to main content

Enrich data with a custom JavaScript function

Project description

datasette-enrichments-quickjs

PyPI Changelog Tests License

Datasette enrichment for enriching data with a custom JavaScript function

Installation

Install this plugin in the same environment as Datasette.

datasette install datasette-enrichments-quickjs

Usage

This enrichment allows you to select rows from a table and specify a custom JavaScript function to use to generate a value for each of those rows, storing that value in a specified column and creating that column if it does not exist.

Code runs in a QuickJS sandbox with a 0.1s time limit for the execution of each function and a 4MB memory limit.

Enrichment JavaScript functions look like this:

function enrich(row) {
    return row["title"] + "!";
}

The return value of your function will be stored in the output column of your choice.

Instead of picking an output column, you can have your function return an object with keys and values.

This example takes a point column with values like 37.7749,-122.4194 and splits it into latitudeandlongitude` columns:

function enrich(row) {
    const bits = row.point.split(",");
    return {
        "latitude": parseFloat(bits[0]),
        "longitude": parseFloat(bits[1])
    }
}

The enrichment will then create new columns in the table for each key in the object returned by that function.

Development

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

cd datasette-enrichments-quickjs
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-enrichments-quickjs-0.1a2.tar.gz (9.6 kB view hashes)

Uploaded Source

Built Distribution

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