Building a Desktop Software program for Datasette

Building a Desktop Software program for Datasette

This week I started experimenting with a desktop application model of Datasette—with the aim of providing those that aren’t chuffed with the boom-line the flexibility to bag Datasette up and running on their possess non-public computers.

Screenshot of the new Datasette desktop app prototype with several open windows

Why a desktop application?

On Monday I kicked off an unlimited Twitter conversation when I posted:

I’m wondering how worthy of the recognition of R amongst some communities when in contrast with Python comes all the way in which down to the truth that with R you might perhaps be ready to put in the RStudio desktop application and you’re prepared to transfer

This ties into my single largest grievance about Python: it’s factual too arduous for folk to bag started with. Developing a Python pattern atmosphere for the first time stays an unlimited barrier to entry.

I later do that in stronger terms:

The extra I take into story this the extra pissed off I bag, taking into account the giant quantity of human capability that’s squandered on story of the barriers to getting started studying to program are so worthy increased than they’ve to be

Which made me mediate of glass houses. My possess Datasette project has precisely the identical exclaim: to poke it within the neighborhood you resolve on to put in Python and then install Datasette! Mac users can use Homebrew, nevertheless telling novices to put in Homebrew first isn’t in particular welcoming either.

Ideally, I’d like of us so that you just can install a conventional desktop application and originate the use of Datasette that strategy, without even desiring to grab that it’s written in Python.

There’s been an originate exclaim to bag Datasette running as a standalone binary the use of PyInstaller since November 2017, with barely a variety of learn.

But I resolve on a UI as properly: I don’t are making an are attempting to beget to coach contemporary users guidelines on how to put in and poke a boom-line application if I can steer obvious of it.

So I made up our minds to use a whereas researching Electron to glimpse how arduous it can well be to manufacture a frequent Datasette desktop application a actuality.

Growth so a long way

The code I’ve written so a long way might perhaps perchance even be stumbled on within the simonw/datasette.app repository on GitHub. The app so a long way does the next:

  • Speed a datasette server on localhost connected to an within the market port (stumbled on the use of portfinder) which terminates when the app quits.
  • Start a desktop window exhibiting that Datasette occasion as soon as the server has started.
  • Enable extra home windows onto the identical occasion to be opened the use of the “Current Window” menu option or the Teach+N keyboard shortcut.
  • Provides an “Start Database…” menu option (and Teach+O shortcut) which brings up a file picker to permit the person to place terminate a SQLite database file to originate—as soon as chosen, right here’s connected to the Datasette occasion and any home windows exhibiting the Datasette homepage are reloaded.

Right here’s a video demo exhibiting these aspects in action:

It’s very worthy an MVP, nevertheless I’m encouraged by the growth so a long way. I mediate right here’s sufficient of a proof of conception to be fee turning this into an proper usable product.

How this all works

There are two formula to the application.

The first is a thin Electron shell, accountable for launching the Python server, managing home windows and configuring the a variety of desktop menu alternate choices outmoded to configure it. The code for that lives in major.js.

The 2d is a custom-made Datasette plugin that provides extra efficiency an crucial by the application. For the time being this consists of a little bit of extra CSS to manufacture the footer follow the underside of the window, and a custom-made API endpoint at /-/originate-database-file which is called by the menu option for opening a brand contemporary database.

Initial impressions of Electron

I ticket it’s frosty to knock Electron, nevertheless on this case it seems like precisely the honest instrument for the job. Datasette is already a internet based application—what I resolve on is a way to hide the configuration of that internet application within the support of an icon, and re-most up-to-the-minute the interface in a strategy that feels extra like a desktop application.

Right here’s my first time constructing something else with Electron—listed below are some of my preliminary impressions.

  • The preliminary getting started workflow is no doubt upright. I started off with their Mercurial Originate and used to be up and running with a barebones application that I might perhaps perchance originate making adjustments to in factual a fast while.
  • The documentation is somewhat upright, nevertheless it leans extra towards being an API reference. I stumbled on myself googling for examples of diversified issues I wished to achieve somewhat incessantly.
  • The automatic making an are attempting out area isn’t gargantuan. I’m the use of Spectron and Mocha for my preliminary (very thin) tests—I bought them up and running in GitHub Actions, nevertheless I’ve already poke into some barriers:
    • For some motive each time I poke the tests an Electron window (and datasette Python route of) is left running. I can’t resolve out why right here’s.
    • There doesn’t seem like a strategy for tests to plight off menu objects, which is maddening on story of quite a bit of the logic I’ve written so a long way deals with menu objects! There might perhaps be an originate exclaim for this dating support to Would possibly perchance well 2016.
  • I haven’t but managed to kit my app. Right here’s clearly going to be the largest exclaim.

Up subsequent: packaging the app

I used to be hoping to bag to this prior to writing up my growth in these weeknotes, nevertheless it appears to be like to be to be like as if it’s going to be rather a exclaim.

In boom to manufacture an installable macOS app (I’ll dive into Dwelling windows later) I wish to achieve the next:

  • Operate a standalone Datasette executable, whole with the custom-made plugin, the use of PyInstaller
  • Signal that binary with an Apple developer certificate
  • Operate an Electron application that bundles a copy of that datasette binary
  • Signal the resulting Electron application

I’m gazing for figuring this out to be a prolonged-winded and frustrating skills, which is extra the fault of Apple than of Electron. I’m tracking my growth on this in exclaim #7.

Datasette 0.59a2

I pushed out a brand contemporary alpha of Datasette earlier this week, partly driven by work I used to be doing on datasette.app.

The largest contemporary feature on this open is a brand contemporary plugin hook: register_commands()—which lets plugins add extra instructions to Datasette, e.g. datasette take a look at title-of-file.db.

I launched a brand contemporary plugin that workout routines this hook known as datasette-take a look at. Past skills has confirmed me that it’s an crucial to ship an example plugin alongside a brand contemporary hook, to support verify that the hook carry out is fit for aim.

It appears to be like to be I didn’t need this for datasette.app after all, nevertheless it’s silent a gargantuan capability to beget!

sqlite-utils 3.17

Quoting the open notes in fleshy:

  • The sqlite-utils memory boom has a brand contemporary --analyze option, which runs the equal of the analyze-tables boom without delay against the in-memory database created from the incoming CSV or JSON files. (#320)
  • sqlite-utils insert-files now has the flexibility to insert file contents in to TEXT columns as well to the default BLOB. Proceed the --textual content option or use content_text as a column specifier. (#319)

evernote-to-sqlite 0.3.2

As a discover-as much as final week’s work on my non-public Dogsheep, I made up our minds to re-import my Evernote notes… and stumbled on out that Evernote has modified their export mechanism in ways that broke my instrument. Most concerningly their exported XML is even much less properly-fashioned than it outmoded to be. This contemporary open works round that.

TIL this week

Releases this week

Study Extra

Share your love