25

I am making a simple sqlite database for storing some non-sensitive client information. I am very familiar with python+sqlite and would prefer to stick with this combo on this project. I would like to create an simple GUI interface for data entry and searching of the database... something very similar to what MS Access provides. I want my wife to be able to enter/search data easily, so PHPmyadmin style things are out of the question.

I understand I could just give in and get MS Access, but if reasonbly possible would rather just write the code myself so it will run on my computers (*nix) and is flexible (so I can later integrate it with a web application and our smart phones.)

Can you developers recommend any interfaces/packages/etc (preferably pythonic) that can accomplish this with reasonable ease?

Thanks!

Tony Toews
  • 7,850
  • 1
  • 22
  • 27
Geraldo
  • 251
  • 1
  • 3
  • 3
  • 1
    I don't think there's any purpose served in having the MS-ACCESS tag here, as those experienced with Access are not going to be providing you with any help in going with something else. – David-W-Fenton Jul 01 '11 at 01:36
  • 7
    I humbly disagree, because those experienced with MS-ACCESS may *wish* they *could* go with something else, and this question provides some framework of solutions to that end. I myself am familiar with Access, and yet, here I am :) Best – Geraldo Aug 01 '11 at 00:35

2 Answers2

11

Since you're interested in future integration with a web application, you might consider using a Python web framework and running the app locally on your machine, using your web browser as the interface. In that case, one easy option would be web2py. Just download, unzip, and run, and you can use the web-based IDE (demo) to create a simple CRUD app very quickly (if you really want to keep it simple, you can even use the "New application wizard" (demo) to build the app). It includes its own server, so you can run your app locally, just like a desktop app.

You can use the web2py DAL (database abstraction layer) to define and create your SQLite database and tables (without writing any SQL). For example:

db = DAL('sqlite://storage.db')

db.define_table('customer',
    Field('name', requires=IS_NOT_IN_DB(db, 'customer.name')),
    Field('address'),
    Field('email', requires=IS_EMAIL()))

The above code will create a SQLite database called storage.db and create a table called 'customer'. It also specifies form validators for the 'name' and 'email' fields, so whenever those fields are filled via a form, the entries will be validated ('name' cannot already be in the DB, and 'email' must be a valid email address format) -- if validation fails, the form will display appropriate error messages (which can be customized).

The DAL will also handle schema migrations automatically, so if you change your table definitions, the database schema will be updated (if necessary, you can turn off migrations completely or on a per table basis).

Once you have your data models defined, you can use web2py's CRUD system to handle all the data entry and searching. Just include these two lines (actually, they're already included in the 'welcome' scaffolding application):

from gluon.tools import Crud
crud = Crud(db)

And in a controller, define the following action:

def data():
    return dict(form=crud())

That will expose a set of pre-defined URLs that will enable you to create, list, search, view, update, and delete records in any table.

Of course, if you don't like some of the default behavior, there are lots of ways to customize the CRUD forms/displays, or you can use some of web2py's other forms functionality to build a completely custom interface. And web2py is a full-stack framework, so it will be easy to add functionality to your app as your needs expand (e.g., access control, notifications, etc.).

Note, web2py requires no installation or configuration and has no dependencies, so it's very easy to distribute your app to other machines -- just zip up the entire web2py folder (which will include your app folder) and unzip it on another machine. It will run on *nix, Mac, and Windows (on Windows, you will either need to install Python or download the web2py Windows binary instead of the source version -- the Windows binary includes its own Python interpreter).

If you have any questions, there's a very helpful and responsive mailing list. You might also get some ideas from some existing web2py applications.

Anthony
  • 25,466
  • 3
  • 28
  • 57
3

I normally use GTK+ that has well documented Python bindings.

The biggest advantage is that you can use a fairly intuitive GUI editor (Glade) and automagically link callbacks to events (to be honest most other major graphical toolkits have this possibility too, like for example QT, but my perception is that GTK+ enjoys wider adoption in the Python community). EDIT: additionally GTK is used by Gnome and many other desktop environments (KDE uses QT though).

That said, if all you need is truly just data insertion from a trusted person, you could use something already done like SQLite manager (it's a FireFox plugin).


Radically alternative solution: use django and you can literally pass from reading the tutorial to have your app up and running in a matter of hours, inclusive of user authentications, back-end administrative interface etc. (your project is exactly what I did with it to allow my wife to insert expenses in our family budget).

Django is written in Python and you can use SQLite as a back-end.

mac
  • 42,153
  • 26
  • 121
  • 131