Easy form building for terminal windows: jsonwidget-python

I’ve been working on a project to make building forms really simple. My latest work is “jsonwidget-python” for terminal-based applications (like you would use via SSH or local terminal on Linux and Mac). It’s all very retro, but terminal windows are still very much in use for buzzword-compliant activities like configuring virtual machines for cloud computing, in addition to being the preferred user interface for a lot of people out there (*cough* nerds *cough*).

This new project builds on some earlier work that I’ve retroactively renamed “jsonwidget-javascript“. jsonwidget-javascript is AJAX-y generation of forms inside a browser based on a JSON schema. jsonwidget-python is intended for terminal users at first, but will extend to other contexts as well.

Here’s a simple screenshot to show what’s going on:

Simple Address Entry in jsonwidget-python
Simple Address Entry in jsonwidget-python


There’s nothing too fancy in this screenshot, but this is probably the most typical case. What you see there is deceptively simple, but there’s a lot of complicated stuff going on under the hood. Most of the complicated parts (drawing the fields, handling focus, handling keyboard shortcuts) is being provided by urwid, an excellent Python-based library for building terminal-based user interfaces. jsonwidget is providing a further abstraction that hopefully makes it even simpler to provide this type of interface, though sacrificing much of the flexibility of programming directly against urwid. Here is the complete configuration file (the schema) describing that address entry form, as well as the documentation for the schema format. jsonwidget-python is compatible with jsonwidget-javascript, so the same schema also works in jsonwidget-javascript.

jsonwidget-javascript screenshot with simple address entry form
jsonwidget-javascript screenshot with the same simple address entry form
One nice feature on display even in the simple demo is the ability to have arrays as fields. You’ll notice that the phone number field has two phone numbers, and offers to let you add a third. There’s no artificial limit on the number of phone numbers that one can enter using this tool, beyond the usual limits of computer memory, patience, etc.

It also handles more complicated schemas if your application calls for it. For example, let’s say that one wanted to build a real address book application. Clearly a lot more flexibility would be needed than merely allowing multiple phone numbers. Here’s a screenshot showing a much more sophisticated schema that’s more like what real address book applications allow:

More complicated data entry with jsonwidget-python
More complicated data entry with jsonwidget-python

So, what is this good for? Well, I think it’ll be good for a lot of stuff. I suspect it might be a very good user interface to stick in front of a augeas-based user interface. I think it might also be a good tool for building a terminal-based frontend for editing CouchDB and similar databases. In particular, I’m thinking about making a desktop-couch interface for contact editing. Another idea I’ve dabbled with is automatically building a UI based on parameters to Python’s optparse. Yet another thought is an editor for Python’s ConfigParser or alternatively ConfigObj. Lots of different possibilities here.

I’m particularly interested in suggestions for applications that people would use. So, if you have an application for this type of thing that you’re reasonably sure you’d use if I did a good enough job implementing, let me know.

Of course, that’s probably getting a little ahead of myself. There’s a number of things on the roadmap to do, such as more kosher packaging for easy_install and for Linux distros, as well as the ability to edit arbitrary JSON. I also need to investigate SitePen’s JSON schema work, which they appear to be well along toward some sort of RFC (probably informational, but that can be enough for something like this).

Anyway, if this sort of thing is up your alley, please give it a whirl and let me know what you think. You can download jsonwidget-python and give it a spin. I’ve set up a jsonwidget mailing list which you’re more than welcome to use, but you can also just post a comment here or contact me via email.

Update: March 9 – there’s now several ways of getting jsonwidget:

2 thoughts on “Easy form building for terminal windows: jsonwidget-python

  1. Great post! You really made a point here. Data entry with jsonwidget-python is too complicated even for me.

  2. Heya i’m for the primary time here. I found this board and I to find It truly helpful & it helped me out much. I hope to give one thing back and aid others such as you helped me.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s