Chapter 11. Persistence and Databases
Python supports several ways of persisting data. One way, serialization, views data as a collection of Python objects. These objects can be serialized (saved) to a byte stream, and later deserialized (loaded and re-created) back from the byte stream. Object persistence lives on top of serialization, adding features such as object naming. This chapter covers the Python modules that support serialization and object persistence.
Another way to make data persistent is to store it in a database (DB). One simple category of DBs are just file formats that use keyed access to enable selective reading and updating of relevant parts of the data. This chapter covers Python standard library modules that support several variations of such a file format, known as DBM.
A relational DB management system (RDBMS), such as PostgreSQL or Oracle, offers a more powerful approach to storing, searching, and retrieving persistent data. Relational DBs rely on dialects of Structured Query Language (SQL) to create and alter a DB’s schema, insert and update data in the DB, and query the DB with search criteria. (This book does not provide reference material on SQL. We recommend SQL in a Nutshell, by Kevin Kline [O’Reilly].) Unfortunately, despite the existence of SQL standards, no two RDBMSes implement exactly the same SQL dialect.
The Python standard library does not come with an RDBMS interface. However, many third-party modules let your Python programs access a specific ...
Get Python in a Nutshell, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.