Databases, GUIs, and Python
Any application that exhibits any complexity contains something that could be called a database: structured data that is persisted between invocations of the application. Uses range from the dedicated object databases that constitute a word-processor document, to the vanilla tables and files of a payroll application. However, when people talk about database-based applications, they mostly think of a basic two- or three-tier architecture: a relational database, a GUI front end, and perhaps a middle layers.
Now that Python has grown up, it has to hold its own in this area against corporate heavyweights such as Java, Visual Basic, or any of the proprietary solutions such as Oracle Forms. This article examines the possibilities, strengths, and weaknesses of Python in the area of two- and three-tier database applications.
The simplest way to store your data is to use key-value pairs. Python's native dictionary type makes this possible. Using one of the standard modules, such as pickle, shelve, or anydbm, you can store your data in a platform-independent file format.
It is quite easy to create a simple file-based database with multiple indexes using only Python dictionaries and pickle. If the needs of your GUI or Web application are simplethat is, if you don't need many dynamically built queries over many tablesyou can use such a back end instead of a real database. An example is the textdb back end for the dbobj database wrapper model I have developed.