This release is a pre-release and may not be stable for production use.
datasette-enrichments-quickjs
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
Release files for datasette-enrichments-quickjs 0.1a2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| datasette-enrichments-quickjs-0.1a2.tar.gz | 9.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| datasette_enrichments_quickjs-0.1a2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 18.7 kB
Release files / datasette-enrichments-quickjs-0.1a2.tar.gz
| Download URL | datasette-enrichments-quickjs-0.1a2.tar.gz |
|---|---|
| Size | 9.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
20e79bc8e93c720b15afff028ddf1f2fb0451271a0e01b6caafa138e7b2f2c18
|
|
BLAKE2b-256 checksum How to use checksums |
3e2d04baadc71a566372e245893d0c4ceb565eb77d6cd3be5de88824840914b9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.0.0 CPython/3.12.2
|
Release files / datasette_enrichments_quickjs-0.1a2-py3-none-any.whl
| Download URL | datasette_enrichments_quickjs-0.1a2-py3-none-any.whl |
|---|---|
| Size | 9.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
343bbc9b0e44e6fbfeb9cd1bc68803196e0136cdcce35a0df193190a490b9a01
|
|
BLAKE2b-256 checksum How to use checksums |
419fdaf604e4082ac6e0e65278109ef33229f9f604f0f9b19a8e7df8aa5ca70e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.0.0 CPython/3.12.2
|