< BACKMake Note | BookmarkCONTINUE >
152015024128143245168232148039199167010047123209178152124239215162147044209056133069164150

Working with Databases

For simplicity, let's say that databases are summarized as the place where you store and update data. Python is able to connect to a wide variety of databases.

The simplest solution to handle databases in Python is to use plain text files. A tiny variation of this method is to store the information in binary format.

The next possible solution is to use the indexing mechanism provided by the dbm-like modules. This mechanism provides better performance than our first option because it automatically organizes the data. It works by implementing dictionary structures that are used to store information. This option enables you to encode Python objects, and efficiently archive them in indexed files without having to go through the details of parsing and unparsing the information.

For this reason, object serialization and persistence storing are also present in this chapter. Both concepts are very helpful when it comes to storing information. Their roles are to translate Python objects to strings before archiving them to the file system or before transferring them to another process.

The last solution is to use "real" databases'systems by importing third-party database extension modules, such as the native Python interfaces to MySQL, Oracle, and Sybase database systems.

If your database doesn't have a native interface to Python, don't worry. Python also offers ODBC extensions that will enable you to connect to any database that supports ODBC, and as you know, almost all database servers have ODBC drivers available nowadays.

In the worst-case scenario, many client/server database systems provide C libraries that connect to their databases. If you are a dedicated hacker, you can create extension modules that talk to these C libraries connecting to the database.

For more information about using databases versus Python, check Python's Web site at the following URL:

http://www.python.org/topics/database/


Last updated on 1/30/2002
Python Developer's Handbook, © 2002 Sams Publishing

< BACKMake Note | BookmarkCONTINUE >

Index terms contained in this section

databases

© 2002, O'Reilly & Associates, Inc.