mapping results into dictionaries common issue concerning database results is the mapping of tuples or lists into dictionary of named fields for exampleif the result set of query contains large number of columnsit may be easier to work with this data using descriptive field names instead of hard-coding the numeric index of specific fields within tuple there are many ways to handle thisbut one of the most elegant ways to process result data is through the use of generator functions for exampledef generate_dicts(cur)import itertools fieldnames [ [ lower(for in cur description while truerows cur fetchmany(if not rowreturn for row in rowsyield dict(itertools izip(fieldnames,row)sample use cur execute("select namesharesprice from portfolio"for in generate_dicts(cur)print ['name'], ['shares'], ['price'be aware that the naming of columns is not entirely consistent between databases-especially with respect to things such as case sensitivity soyou'll need to be little careful if you try to apply this technique to code that' meant to work with variety of different database modules database api extensions finallymany extensions and advanced features can be added to specific database modules--for examplesupport for two-phase commits and extended error handling pep- has additional information about the recommended interface for these features and should be consulted by advanced users third-party library modules also may simplify the use of relational database interfaces sqlite module the sqlite module provides python interface to the sqlite database library (attractive for various reasons for oneit does not rely upon separate database server nor does it require any kind of special configuration--you can start to use it right away in your programs by simply connecting to database file (and if it doesn' exista new file is createdthe database also supports transactions for improved reliability (even across system crashesas well as locking to allow the same database file to be simultaneously accessed from multiple processes the programming interface to the library follows the conventions described in the previous section on the database apiso much of that detail is not repeated here insteadthis section focuses on the technical details of using this module as well as features that are specific to the sqlite module lib fl ff