datasette-enrichments-quickjs


Namedatasette-enrichments-quickjs JSON
Version 0.1a2 PyPI version JSON
download
home_pageNone
SummaryEnrich data with a custom JavaScript function
upload_time2024-04-05 22:08:22
maintainerNone
docs_urlNone
authorSimon Willison
requires_python>=3.8
licenseApache-2.0
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # datasette-enrichments-quickjs

[![PyPI](https://img.shields.io/pypi/v/datasette-enrichments-quickjs.svg)](https://pypi.org/project/datasette-enrichments-quickjs/)
[![Changelog](https://img.shields.io/github/v/release/datasette/datasette-enrichments-quickjs?include_prereleases&label=changelog)](https://github.com/datasette/datasette-enrichments-quickjs/releases)
[![Tests](https://github.com/datasette/datasette-enrichments-quickjs/actions/workflows/test.yml/badge.svg)](https://github.com/datasette/datasette-enrichments-quickjs/actions/workflows/test.yml)
[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/datasette/datasette-enrichments-quickjs/blob/main/LICENSE)

[Datasette enrichment](https://github.com/simonw/datasette-enrichments) for enriching data with a custom JavaScript function

## Installation

Install this plugin in the same environment as Datasette.
```bash
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](https://github.com/PetterS/quickjs) with a 0.1s time limit for the execution of each function and a 4MB memory limit.

Enrichment JavaScript functions look like this:

```javascript
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 `latitude` and `longitude` columns:

```javascript
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:
```bash
cd datasette-enrichments-quickjs
python3 -m venv venv
source venv/bin/activate
```
Now install the dependencies and test dependencies:
```bash
pip install -e '.[test]'
```
To run the tests:
```bash
pytest
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "datasette-enrichments-quickjs",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": null,
    "author": "Simon Willison",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/3e/2d/04baadc71a566372e245893d0c4ceb565eb77d6cd3be5de88824840914b9/datasette-enrichments-quickjs-0.1a2.tar.gz",
    "platform": null,
    "description": "# datasette-enrichments-quickjs\n\n[![PyPI](https://img.shields.io/pypi/v/datasette-enrichments-quickjs.svg)](https://pypi.org/project/datasette-enrichments-quickjs/)\n[![Changelog](https://img.shields.io/github/v/release/datasette/datasette-enrichments-quickjs?include_prereleases&label=changelog)](https://github.com/datasette/datasette-enrichments-quickjs/releases)\n[![Tests](https://github.com/datasette/datasette-enrichments-quickjs/actions/workflows/test.yml/badge.svg)](https://github.com/datasette/datasette-enrichments-quickjs/actions/workflows/test.yml)\n[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/datasette/datasette-enrichments-quickjs/blob/main/LICENSE)\n\n[Datasette enrichment](https://github.com/simonw/datasette-enrichments) for enriching data with a custom JavaScript function\n\n## Installation\n\nInstall this plugin in the same environment as Datasette.\n```bash\ndatasette install datasette-enrichments-quickjs\n```\n## Usage\n\nThis 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.\n\nCode runs in a [QuickJS sandbox](https://github.com/PetterS/quickjs) with a 0.1s time limit for the execution of each function and a 4MB memory limit.\n\nEnrichment JavaScript functions look like this:\n\n```javascript\nfunction enrich(row) {\n    return row[\"title\"] + \"!\";\n}\n```\nThe return value of your function will be stored in the output column of your choice.\n\nInstead of picking an output column, you can have your function return an object with keys and values.\n\nThis example takes a `point` column with values like `37.7749,-122.4194 and splits it into `latitude` and `longitude` columns:\n\n```javascript\nfunction enrich(row) {\n    const bits = row.point.split(\",\");\n    return {\n        \"latitude\": parseFloat(bits[0]),\n        \"longitude\": parseFloat(bits[1])\n    }\n}\n```\nThe enrichment will then create new columns in the table for each key in the object returned by that function.\n\n## Development\n\nTo set up this plugin locally, first checkout the code. Then create a new virtual environment:\n```bash\ncd datasette-enrichments-quickjs\npython3 -m venv venv\nsource venv/bin/activate\n```\nNow install the dependencies and test dependencies:\n```bash\npip install -e '.[test]'\n```\nTo run the tests:\n```bash\npytest\n```\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "Enrich data with a custom JavaScript function",
    "version": "0.1a2",
    "project_urls": {
        "CI": "https://github.com/datasette/datasette-enrichments-quickjs/actions",
        "Changelog": "https://github.com/datasette/datasette-enrichments-quickjs/releases",
        "Homepage": "https://github.com/datasette/datasette-enrichments-quickjs",
        "Issues": "https://github.com/datasette/datasette-enrichments-quickjs/issues"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "419fdaf604e4082ac6e0e65278109ef33229f9f604f0f9b19a8e7df8aa5ca70e",
                "md5": "4b193f547f7588c930b674e91e5aea5f",
                "sha256": "343bbc9b0e44e6fbfeb9cd1bc68803196e0136cdcce35a0df193190a490b9a01"
            },
            "downloads": -1,
            "filename": "datasette_enrichments_quickjs-0.1a2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4b193f547f7588c930b674e91e5aea5f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 9133,
            "upload_time": "2024-04-05T22:08:21",
            "upload_time_iso_8601": "2024-04-05T22:08:21.392586Z",
            "url": "https://files.pythonhosted.org/packages/41/9f/daf604e4082ac6e0e65278109ef33229f9f604f0f9b19a8e7df8aa5ca70e/datasette_enrichments_quickjs-0.1a2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3e2d04baadc71a566372e245893d0c4ceb565eb77d6cd3be5de88824840914b9",
                "md5": "67fa23a01d8f6bf6b8039822c660f63a",
                "sha256": "20e79bc8e93c720b15afff028ddf1f2fb0451271a0e01b6caafa138e7b2f2c18"
            },
            "downloads": -1,
            "filename": "datasette-enrichments-quickjs-0.1a2.tar.gz",
            "has_sig": false,
            "md5_digest": "67fa23a01d8f6bf6b8039822c660f63a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 9586,
            "upload_time": "2024-04-05T22:08:22",
            "upload_time_iso_8601": "2024-04-05T22:08:22.849056Z",
            "url": "https://files.pythonhosted.org/packages/3e/2d/04baadc71a566372e245893d0c4ceb565eb77d6cd3be5de88824840914b9/datasette-enrichments-quickjs-0.1a2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-05 22:08:22",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "datasette",
    "github_project": "datasette-enrichments-quickjs",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "datasette-enrichments-quickjs"
}
        
Elapsed time: 0.31033s