Skip to content

Commit

Permalink
Docs for now optional parameters, closes #28
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Nov 28, 2023
1 parent 711593d commit 24a74d0
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion docs/developing.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ async def initialize(
config: dict
):
```
The named parameters passed to `initialize()` are all optional. If you declare them they will be passed as follows:

- `datasette` is the [Datasette instance](https://docs.datasette.io/en/stable/internals.html#datasette-class).
- `db` is the [Database instance](https://docs.datasette.io/en/stable/internals.html#database-class) for the database that the enrichment is being run against.
- `table` is the name of the table.
Expand All @@ -94,13 +96,15 @@ async def enrich_batch(
):
# Enrichment logic goes here
```
Again, you can use just the subset of the named parameters that you need.

This method will be called multiple times, each time with a different list of rows.

It should perform whatever enrichment logic is required, using the `db` object ([documented here](https://docs.datasette.io/en/stable/internals.html#database-class)) to write any results back to the database.

`enrich_batch()` is an `async def` method, so you can use `await` within the method to perform asynchronous operations such as HTTP calls ([using HTTPX](https://www.python-httpx.org/async/)) or database queries.

The arguments passed to `enrich_batch()` are as follows:
The parameters available to `enrich_batch()` are as follows:

- `datasette` is the [Datasette instance](https://docs.datasette.io/en/stable/internals.html#datasette-class). You can use this to read plugin configuration, check permissions, render templates and more.
- `db` is the [Database instance](https://docs.datasette.io/en/stable/internals.html#database-class) for the database that the enrichment is being run against. You can use this to execute SQL queries against the database.
Expand Down Expand Up @@ -151,6 +155,8 @@ Your class can optionally implement a `finalize()` method. This will be called o
async def finalize(self, datasette, db, table, config):
# ...
```
Again, these named parameters are all optional:

- `datasette` is the [Datasette instance]
- `db` is the [Database instance](https://docs.datasette.io/en/stable/internals.html#database-class)
- `table` is the name of the table (a string)
Expand Down

0 comments on commit 24a74d0

Please sign in to comment.