Single File Storage for a Python Application

I am starting to develop a Python application that provides a graphical interface for editing various graphical and numerical objects (this is a configuration and management tool for mobile robots, if you know). One of the questions is how to store data for the project (which means for the robot). The amount of data will be low (about 10 MB max.) And rather heterogeneous (geometric data of the robot, maps, missions, platform logs, recorded sensor data, project preferences, ...).

I do not want to develop my own storage tier. Project data must be stored in a single file and easily accessible from Python. Keeping updates should be cheap: I don’t want to use the explicit β€œSave” operation, and the changes should be saved as soon as they happen.

One ZIP file is probably impractical, and writing a save layer is required to write application objects to the repository. SQLite is an obvious candidate, possibly with SQLAlchemy as an object-relational level. ZODB also looks interesting, but so far I have no experience.

Any recommendations?

EDIT: When I say "application", I mean a program that should be installed on a user computer, not in a web application.

EDIT: I will open data files created by other (not necessarily trusted) people, similar to how I will do with Word or PDF files. It should be a safe operation.

+4
source share
5 answers

I would advise you to take a look at SQLAlchemy as you discussed in your question. You can map tables in SQLite to Python objects. Using a SQLAlchemy session ( http://www.sqlalchemy.org/docs/session.html#what-does-the-session-do ), you can run queries, add objects to tables, and immediately call the session.commit command to to automatically save data in SQLite.

New data item:

ed_user = User('ed', 'Ed Jones', 'edspassword') #user is the class you mapped the table to session.add(ed_user) session.commit() # basically auto saving here :) 

This is what I will use. I am using SQLAlchemy for the project now and as what I see. See here for more details: http://www.sqlalchemy.org/docs/ormtutorial.html#adding-new-objects

+4
source

shelve provides a display interface that allows you to store any kind of pickleable.

+5
source

Pickle it!

Compose your data structures as you like in memory, and then just run them on a brine disk when you want to save.

0
source

Why not give couchdb a try? Since your data is heterogeneous, this is best suited. Easy to use and 10 MB for it nothing: http://pypi.python.org/pypi/CouchDB

0
source

ZODB, which is mentioned by the OP, is the best choice IMHO.

Here is an introductory word of good quality, and you can probably solve it just after reading http://www.ibm.com/developerworks/aix/library/au-zodb/

Note that for replication, as mentioned at the end of this article, ZRS is no longer a closed source commercial, but was an open source.

0
source

All Articles