Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

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

  1. operations — pure, synchronous string surgery (view_lines, str_replace, insert, apply_edits). No I/O, no await, no Datasette.
  2. EditStore — the storage seam. The defining method is edit(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.
    • SqliteVersionedStore runs the transform inside Datasette's write thread (execute_write_fn) and keeps full version history.
    • DiskStore uses a lock + atomic os.replace.
    • S3 (If-Match) and GitHub (sha) backends fit the same shape with a compare-and-set retry loop.
  3. EditToolset — turns any EditStore into Datasette Agent tools with one consistent JSON envelope. Two hooks absorb the plugin-specific parts:
    • id_codec maps internal refs to the ids the model sees (e.g. an artifact- prefix).
    • render optionally injects presentation (e.g. an _html iframe preview); omit it and no *_render tool 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

Metadata

Release files for datasette-agent-edit 0.1a0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for datasette-agent-edit 0.1a0
File Size Uploaded
datasette_agent_edit-0.1a0.tar.gz 19.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for datasette-agent-edit 0.1a0
File Interpreter ABI Platform
datasette_agent_edit-0.1a0-py3-none-any.whl Python 3 none any Details

Total release size: 37.7 kB

Release files / datasette_agent_edit-0.1a0.tar.gz

Download URL datasette_agent_edit-0.1a0.tar.gz
Size 19.3 kB
Tags Source
SHA-256 checksum
How to use checksums
0b183465ec0144da489d0941ac086ec43c115c8867eacde77c1c03bc9a9400c2
BLAKE2b-256 checksum
How to use checksums
7985fedc10ace53cc45317310a4cf94172359bea60671f566d1a6f93f2813428
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 7, 2026.

Transparency log

Release files / datasette_agent_edit-0.1a0-py3-none-any.whl

Download URL datasette_agent_edit-0.1a0-py3-none-any.whl
Size 18.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1658de270642480d66fe8e8462ee2da0f5964cdaac5925378de0037f01327395
BLAKE2b-256 checksum
How to use checksums
323593afc0dfde1a54b260480b0f42d7ee58a926087e8d377be93aff734aa318
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 7, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1a0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page