Storage-agnostic file-editing tools (view / str_replace / insert) for Datasette Agent plugins
Project description
datasette-agent-edit
Storage-agnostic file-editing tools (view / str_replace / insert / batch
edit) for Datasette Agent plugins. The same tool behaviour can sit on top of
any storage layer — SQLite, the local filesystem, S3, the GitHub contents API,
…
The three layers
operations— pure, synchronous string surgery (view_lines,str_replace,insert,apply_edits). No I/O, noawait, no Datasette.EditStore— the storage seam. The defining method isedit(ref, transform): the backend reads the current content, runs your pure transform inside whatever critical section it needs, and persists the result atomically. A failing transform persists nothing.SqliteVersionedStoreruns the transform inside Datasette's write thread (execute_write_fn) and keeps full version history.DiskStoreuses a lock + atomicos.replace.- S3 (
If-Match) and GitHub (sha) backends fit the same shape with a compare-and-set retry loop.
EditToolset— turns anyEditStoreinto Datasette Agent tools with one consistent JSON envelope. Two hooks absorb the plugin-specific parts:id_codecmaps internal refs to the ids the model sees (e.g. anartifact-prefix).renderoptionally injects presentation (e.g. an_htmliframe preview); omit it and no*_rendertool is registered.
Why transform is synchronous
The transform sits between a backend's awaits, never inside them — the SQLite
backend literally cannot await on its write thread, and the S3/GitHub backends
must not re-run network calls on every compare-and-set retry. If an edit
decision needs async work, resolve it first and close over the result:
resolved = await registry.lookup(name)
await store.edit(ref, lambda c: rewrite(c, resolved))
A rare backend that genuinely needs in-transaction async can implement the
optional AsyncTransformStore.aedit capability; the toolset never requires it.
Example
from datasette_agent_edit import EditToolset, SqliteVersionedStore, PrefixCodec
store = SqliteVersionedStore(datasette.get_internal_database())
toolset = EditToolset(
store,
name_prefix="artifact",
id_field="artifact_id",
id_codec=PrefixCodec("artifact-"),
render=lambda editable: {"_html": build_iframe(editable.content, editable.metadata)},
)
agent_tools = toolset.tools() # list of AgentTool, ready to register
Development
uv run pytest
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file datasette_agent_edit-0.1a0.tar.gz.
File metadata
- Download URL: datasette_agent_edit-0.1a0.tar.gz
- Upload date:
- Size: 19.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0b183465ec0144da489d0941ac086ec43c115c8867eacde77c1c03bc9a9400c2
|
|
| MD5 |
735ae416b56317e4ddbc9a0e4b919abd
|
|
| BLAKE2b-256 |
7985fedc10ace53cc45317310a4cf94172359bea60671f566d1a6f93f2813428
|
Provenance
The following attestation bundles were made for datasette_agent_edit-0.1a0.tar.gz:
Publisher:
publish.yml on datasette/datasette-agent-edit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
datasette_agent_edit-0.1a0.tar.gz -
Subject digest:
0b183465ec0144da489d0941ac086ec43c115c8867eacde77c1c03bc9a9400c2 - Sigstore transparency entry: 1753230422
- Sigstore integration time:
-
Permalink:
datasette/datasette-agent-edit@739f96ef3524c8fb1a17706ba293cb0723b77be6 -
Branch / Tag:
refs/tags/0.1a0 - Owner: https://github.com/datasette
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@739f96ef3524c8fb1a17706ba293cb0723b77be6 -
Trigger Event:
release
-
Statement type:
File details
Details for the file datasette_agent_edit-0.1a0-py3-none-any.whl.
File metadata
- Download URL: datasette_agent_edit-0.1a0-py3-none-any.whl
- Upload date:
- Size: 18.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1658de270642480d66fe8e8462ee2da0f5964cdaac5925378de0037f01327395
|
|
| MD5 |
233ee1152e9b61f6d4847d62fb97482f
|
|
| BLAKE2b-256 |
323593afc0dfde1a54b260480b0f42d7ee58a926087e8d377be93aff734aa318
|
Provenance
The following attestation bundles were made for datasette_agent_edit-0.1a0-py3-none-any.whl:
Publisher:
publish.yml on datasette/datasette-agent-edit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
datasette_agent_edit-0.1a0-py3-none-any.whl -
Subject digest:
1658de270642480d66fe8e8462ee2da0f5964cdaac5925378de0037f01327395 - Sigstore transparency entry: 1753230436
- Sigstore integration time:
-
Permalink:
datasette/datasette-agent-edit@739f96ef3524c8fb1a17706ba293cb0723b77be6 -
Branch / Tag:
refs/tags/0.1a0 - Owner: https://github.com/datasette
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@739f96ef3524c8fb1a17706ba293cb0723b77be6 -
Trigger Event:
release
-
Statement type: