Skip to main content

Forward Datasette events to another instance

Project description

datasette-events-forward

PyPI Changelog Tests License

Forward Datasette events to another instance

Installation

Install this plugin in the same environment as Datasette.

datasette install datasette-events-forward

Configuration

Configure the plugin like so:

{
    "plugins": {
        "datasette-events-forward": {
            "api_token": "***",
            "api_url": "https://stats.datasette.cloud/data/-/create",
            "instance": "localhost"
        }
    }
}

The plugin will then gather all events and forward them to the specified instance, adding them to a table called datasette_events which will be created if it does not exist.

The instance key can be used to differentiate different instances that report to the same backend. Events are identified with a ULID to ensure they are unique even across different instances.

Events are forwarded in batches of up to 10, no more than once every 10 seconds.

Full list of configuration settings:

  • api_url: The write API URL of a Datasette instance to forward the events to.
  • api_token: The API token to use when sending events. Use {"$env": "FORWARD_TOKEN"} to read the token from the FORWARD_TOKEN environment variable.
  • instance: A string to identify the instance that is sending the events.

The api_url can be either a https://datasette.example.com/data/datasette_events/-/insert endpoint for inserting rows, or a https://datasette.example.com/data/-/create endpoint for creating a table and inserting rows into it. If the table does not yet exist you should use the /-/create variant, otherwise use the /-/insert variant.

If you use /-/insert your API token just needs insert-row permissions. For /-/create you will need create-table permissions as well.

And to control the rate at which batches of events are sent to the Datasette write API:

  • batch_limit: The number of events to send in each batch, defaults to 10. The Datasette write API has a 100 row limit by default so this should be set to a value less than that.
  • max_rate: The maximum number of deliver HTTP requests to send in the specified time period, defaults to 1.
  • time_period: The time period for the rate limiting in seconds, defaults to 10.

Development

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

cd datasette-events-forward
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-events-forward-0.1a0.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

datasette_events_forward-0.1a0-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file datasette-events-forward-0.1a0.tar.gz.

File metadata

File hashes

Hashes for datasette-events-forward-0.1a0.tar.gz
Algorithm Hash digest
SHA256 18816f2bf2e48c3ba95183e4f67bcadbd05bae020462e599ea0438d62ab95414
MD5 7b8b13d2aea5dccf16074ce8ccf10c58
BLAKE2b-256 662b40521fc04de632bc508672a01832315906776c896ce4703653071e9e521d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for datasette_events_forward-0.1a0-py3-none-any.whl
Algorithm Hash digest
SHA256 6d46ce05d0ef9afdbab4599ed59224abc5e2f57ee93895dcdb8384d832c726df
MD5 d59f7e603342c3f4642b85888a0b50a6
BLAKE2b-256 ff6a10734da87295c3305568e661218234bba7dc6128bbb34ab994ac1fccafae

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