Datasette’s new JSON write API: The first alpha of Datasette 1.0
simonwillison.net
simonwillison.net
My new demo also then pipes that data up to Datasette using curl -X POST - this script here: https://github.com/simonw/scrape-hacker-news-by-domain/blob/...
As hinted in the opening, I am wondering if I could utilize the new API as a low-performance alternative to Redis. All of the SQLite guarantees, easy network access, and optionally backups through Litestream.
If/when the “library” feature gets incorporated, I could even imagine something crazy like using a library of SQLite databases to handle different backing services. ‘Redis’ cache server, job scheduler, log endpoint. Madness, but these are the idle thoughts before the caffeine has fully circulated.
Since I found out about sqlite-utils being able to trivially put JSON into a sqlite database without needing to stop and write out a whole schema, I've used it a few times. In the process I did think to myself, "why isn't there anything that just lets me dump JSON into an endpoint?". I didn't get around to doing it, and I actually thought maybe it wasn't such a great idea if it hadn't been done yet, because it seemed so obvious. Glad to see I'm not crazy :)
The flexibility and ease of getting different output formats (including charts!) from Datasette is something I hadn't considered, and it looks amazing!
It would need to be an explicit opt-in thing because I've seen what happens if you release software that is open by default, and it's not good!
That is, I might want to be able to append data without any ceremony (logs?), but schema changes or data mutation would require credentials.
But maybe a mechanism for easily specifying that for anonymous localhost users would be useful too?
Yeah that's a good call: I need to do these checks only based on IP.
I could allow users to enter host names which I would resolve to the IP before checking though, which matches how networking is used in things like Kubernetes.
I think this mutation capability would be great for some of my data logging workflows. I push json formatted telemetry data from different types of devices/sensors over tailscale to a central collector. Combined with clickhouse's adapter to sqlite databases, this could make for a very nice self-contained data reporting framework where all the source data flows through datasette to a set of sqlite files organized by topic. It will be important to me in deploying new event senders to have straightforward authentication I can bake pre-authenticated connection schemes into standard images that are installed without customization. Alternatively, configuring datasette so a specific set of ip addresses / cidrs is just granted insert to specific dbs/tables would work fine.
Thanks again. Great stuff!