datasette-cookies-for-magic-parameters


Namedatasette-cookies-for-magic-parameters JSON
Version 0.1.2 PyPI version JSON
download
home_pagehttps://github.com/simonw/datasette-cookies-for-magic-parameters
SummaryUI for setting cookies to populate magic parameters
upload_time2023-01-12 19:05:54
maintainer
docs_urlNone
authorSimon Willison
requires_python>=3.7
licenseApache License, Version 2.0
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # datasette-cookies-for-magic-parameters

[![PyPI](https://img.shields.io/pypi/v/datasette-cookies-for-magic-parameters.svg)](https://pypi.org/project/datasette-cookies-for-magic-parameters/)
[![Changelog](https://img.shields.io/github/v/release/simonw/datasette-cookies-for-magic-parameters?include_prereleases&label=changelog)](https://github.com/simonw/datasette-cookies-for-magic-parameters/releases)
[![Tests](https://github.com/simonw/datasette-cookies-for-magic-parameters/workflows/Test/badge.svg)](https://github.com/simonw/datasette-cookies-for-magic-parameters/actions?query=workflow%3ATest)
[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/simonw/datasette-cookies-for-magic-parameters/blob/main/LICENSE)

UI for setting cookies to populate magic parameters

## Installation

Install this plugin in the same environment as Datasette.

    datasette install datasette-cookies-for-magic-parameters

## Usage

This plugin only affects canned queries. If you have a canned query configured like this:

```yaml
databases:
  mydatabase:
    queries:
      api_query:
        sql: select 'Your API key is' || :_cookie_openai_api_token;
```
Then the `/mydatabase/api_query` page will include a new interface for setting the `openapi_api_token` cookie, or unsetting it if it has already been set.

## Why use this?

This plugin was initially developed to use with [datasette-openai](https://github.com/simonw/datasette-openai) - a plugin that provides custom SQL functions that take an API token as one of their parameters.

Passing these API tokens in a GET query string is unsafe, as they may leak through referrers or other log files.

Instead, this plugin enables them to be set and passed using a cookie, which is much less likely to be logged.

This pattern takes advantage of the `:_cookie_x` feature of Datasette's [magic parameters](https://docs.datasette.io/en/stable/sql_queries.html#magic-parameters) mechanism.

## Development

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

    cd datasette-cookies-for-magic-parameters
    python3 -m venv venv
    source venv/bin/activate

Now install the dependencies and test dependencies:

    pip install -e '.[test]'

To run the tests:

    pytest

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/simonw/datasette-cookies-for-magic-parameters",
    "name": "datasette-cookies-for-magic-parameters",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "",
    "author": "Simon Willison",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/dc/78/9d0f2f8ae1f5b609358cfcdb8affaa88cffe8d11f1492eb40d86ba93d3f1/datasette-cookies-for-magic-parameters-0.1.2.tar.gz",
    "platform": null,
    "description": "# datasette-cookies-for-magic-parameters\n\n[![PyPI](https://img.shields.io/pypi/v/datasette-cookies-for-magic-parameters.svg)](https://pypi.org/project/datasette-cookies-for-magic-parameters/)\n[![Changelog](https://img.shields.io/github/v/release/simonw/datasette-cookies-for-magic-parameters?include_prereleases&label=changelog)](https://github.com/simonw/datasette-cookies-for-magic-parameters/releases)\n[![Tests](https://github.com/simonw/datasette-cookies-for-magic-parameters/workflows/Test/badge.svg)](https://github.com/simonw/datasette-cookies-for-magic-parameters/actions?query=workflow%3ATest)\n[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/simonw/datasette-cookies-for-magic-parameters/blob/main/LICENSE)\n\nUI for setting cookies to populate magic parameters\n\n## Installation\n\nInstall this plugin in the same environment as Datasette.\n\n    datasette install datasette-cookies-for-magic-parameters\n\n## Usage\n\nThis plugin only affects canned queries. If you have a canned query configured like this:\n\n```yaml\ndatabases:\n  mydatabase:\n    queries:\n      api_query:\n        sql: select 'Your API key is' || :_cookie_openai_api_token;\n```\nThen the `/mydatabase/api_query` page will include a new interface for setting the `openapi_api_token` cookie, or unsetting it if it has already been set.\n\n## Why use this?\n\nThis plugin was initially developed to use with [datasette-openai](https://github.com/simonw/datasette-openai) - a plugin that provides custom SQL functions that take an API token as one of their parameters.\n\nPassing these API tokens in a GET query string is unsafe, as they may leak through referrers or other log files.\n\nInstead, this plugin enables them to be set and passed using a cookie, which is much less likely to be logged.\n\nThis pattern takes advantage of the `:_cookie_x` feature of Datasette's [magic parameters](https://docs.datasette.io/en/stable/sql_queries.html#magic-parameters) mechanism.\n\n## Development\n\nTo set up this plugin locally, first checkout the code. Then create a new virtual environment:\n\n    cd datasette-cookies-for-magic-parameters\n    python3 -m venv venv\n    source venv/bin/activate\n\nNow install the dependencies and test dependencies:\n\n    pip install -e '.[test]'\n\nTo run the tests:\n\n    pytest\n",
    "bugtrack_url": null,
    "license": "Apache License, Version 2.0",
    "summary": "UI for setting cookies to populate magic parameters",
    "version": "0.1.2",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7042f4163ba1b15801bdf5c8d4a397ccdfc577dd9c6ff823ba4dce6a537b6c91",
                "md5": "a11ef2466b032217c76045e34d7b4d3e",
                "sha256": "45d79e11e08efa38c108f12fc32fddea7d16ce84c22d2199e7dd6e64be34442d"
            },
            "downloads": -1,
            "filename": "datasette_cookies_for_magic_parameters-0.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a11ef2466b032217c76045e34d7b4d3e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 8642,
            "upload_time": "2023-01-12T19:05:53",
            "upload_time_iso_8601": "2023-01-12T19:05:53.105000Z",
            "url": "https://files.pythonhosted.org/packages/70/42/f4163ba1b15801bdf5c8d4a397ccdfc577dd9c6ff823ba4dce6a537b6c91/datasette_cookies_for_magic_parameters-0.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "dc789d0f2f8ae1f5b609358cfcdb8affaa88cffe8d11f1492eb40d86ba93d3f1",
                "md5": "080b3fa049e1354c76742b47a05087b7",
                "sha256": "0e16376e9217b0c8749b5148ccecc59f16f70e0275359857fe5ff6dabdedd3b4"
            },
            "downloads": -1,
            "filename": "datasette-cookies-for-magic-parameters-0.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "080b3fa049e1354c76742b47a05087b7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 7997,
            "upload_time": "2023-01-12T19:05:54",
            "upload_time_iso_8601": "2023-01-12T19:05:54.329888Z",
            "url": "https://files.pythonhosted.org/packages/dc/78/9d0f2f8ae1f5b609358cfcdb8affaa88cffe8d11f1492eb40d86ba93d3f1/datasette-cookies-for-magic-parameters-0.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-01-12 19:05:54",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "simonw",
    "github_project": "datasette-cookies-for-magic-parameters",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "datasette-cookies-for-magic-parameters"
}
        
Elapsed time: 0.02658s