Re:Datasette’s new JSON write API: The first alpha of Datase...
by simonw on Friday December 02, 2022 @06:55PM
(#33838607)
I'm really pleased with the Hacker News scraping demo in this - it's an extension of the scraper I wrote back in March, using shot-scraper to execute JavaScript in headless Chrome and write the resulting JSON back to a Git repo: https://simonwillison.net/2022/Mar/14/scraping-web-pages-sho...
Re:Datasette’s new JSON write API: The first alpha of Datase...
by etrepum on Friday December 02, 2022 @07:09PM
(#33838719)
Just a small note on the shot-scraper post (very cool stuff!): You can use Array.from(xs, fn) instead of Array.from(xs).map(fn). Same semantics but it happens in one pass with less garbage.
Re:Datasette’s new JSON write API: The first alpha of Datase...
by pedrovhb on Friday December 02, 2022 @07:55PM
(#33839076)
That is really cool, and I'll definitely be using it!
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!
Re:Datasette’s new JSON write API: The first alpha of Datase...
by simonw on Friday December 02, 2022 @08:03PM
(#33839131)
Something I've been contemplating is if I should add a mode that lets you make unauthenticated write API calls from localhost - like Redis and MongoDB do.
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!
Re:Datasette’s new JSON write API: The first alpha of Datase...
by pedrovhb on Friday December 02, 2022 @08:24PM
(#33839299)
Or a bit more generically, having a configurable allowlist of hosts, so I can make my ESP32 just a dumb "sensors on a microcontroller" thing pushing data to a RPi on my local home network, which has static IPs provided to certain devices via DHCP. Having to add an auth header isn't a great deal of work, but it'd be handy to be able to try things out quickly. IMO the great thing about all this is how frictionless it is.
Re:Datasette’s new JSON write API: The first alpha of Datase...
by simonw on Saturday December 03, 2022 @02:25AM
(#33841488)
You mean the HTTP host header?
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.
Re:Datasette’s new JSON write API: The first alpha of Datase...
by fbdab103 on Friday December 02, 2022 @08:11PM
(#33839195)
I like the idea of having some way to do unauthenticated calls, but would it be possible to layer on some additional granularity or would that be asking too much when the security infrastructure already exists?
That is, I might want to be able to append data without any ceremony (logs?), but schema changes or data mutation would require credentials.
Re:Datasette’s new JSON write API: The first alpha of Datase...
by simonw on Friday December 02, 2022 @08:18PM
(#33839247)
The big feature in the next alpha will be the ability to create tokens that have a subset of permissions - eg can only write to specific tables: https://github.com/simonw/datasette/issues/1855
But maybe a mechanism for easily specifying that for anonymous localhost users would be useful too?
Re:Datasette’s new JSON write API: The first alpha of Datase...
by fbdab103 on Friday December 02, 2022 @08:00PM
(#33839107)
Very satisfied Datasette user here. There is no better way to immediately share structured data with a minimum of infrastructure. I have personally used it on tables with 20-50 million rows without issue.
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.
Re:Datasette’s new JSON write API: The first alpha of Datase...
by simonw on Friday December 02, 2022 @08:19PM
(#33839258)
I'd never really thought about it as an alternative for Redis, but yeah if you can handle the huge performance decrease (which for many projects I imagine wouldn't matter in the slightest) that could maybe work pretty well!
Re:Datasette’s new JSON write API: The first alpha of Datase...
by fbdab103 on Saturday December 03, 2022 @12:43PM
(#33845391)
Heh, well I am a solo developer with very low performance requirements so fewer moving pieces is the name of the game. Redis Just Works, but is yet another thing to manage. I know how to query SQL – I interface with Redis so infrequently I have to lookup the commands every time.
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.
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/...
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!
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.
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?
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.