The Python serializer

The lino.utils.dpy module defines Lino's Python serializer and deserializer, which is used for writing and loading demo data, making backups and migrating databases.

Concept and implementation is one of the important concepts which Lino adds to a Django project. It is fully the author's work, and we didn't yet find a similar approach in any other framework 1. In March 2009 Luc suggested to merge it into Django or make it available outside of Lino as well (#10664), but that idea is sleeping since then.

A serializer is run by the dumpdata command and writes data into a file which can be used as a fixture. A deserializer is run by loaddata and loads fixtures into the database.

Basic idea:

When a Lino application starts up, it sets your SERIALIZATION_MODULES setting to {"py" : "lino.utils.dpy"}. This tells Django to associate the .py ending to the lino.utils.dpy.Deserializer class when loading ("deserializing") fixtures.

This deserializer` expects every Python fixture to define a global function objects which it expects to return (or yield) the list of model instances to be added to the database.



Though the basic idea of using Python language to describe data collections is not new. For example Limodou published a Djangosnippet in 2007 which does something similar: - for dumping and loading data from database. Or Why using factories in Django.