Save and access data#

To store data persistently, a process called serialisation or marshalling can be used. In it, data structures are converted into a linear form and stored. The reverse process is then called deserialisation or unmarshalling. Python offers several modules in the standard library that you can be used to serialise and deserialise objects:

the marshal module

is mainly used internally by Python and should not be used to store data in a backwards compatible way.

the pickle module

if you don’t need a readable format or interoperability.

the json module

you can use to exchange data for different languages in a readable form.

the xml module

you can also use to exchange data in different languages in a readable form.

The Python Database API#

The Python Database API defines a standard interface for Python database access modules. It’s defined in PEP 249 and widely used, for example by sqlite, psycopg, and mysql-python.


SQLAlchemy is a widely used database toolkit. It provides not only an ORM but also a generalised API for writing database-agnostic code without SQL. Alembic is based on SQLAlchemy and serves as a database migration tool.

NoSQL databases#

There is data that is difficult to transfer into a relational data model. At the least then you should take a look at NoSQL databases.