I'm writing a basic membership web app in python.
Is it always bad practice to abandon databases completely and simply pickle a python dictionary to a file (http://docs.python.org/2/library/pickle.html)? The program should never have to deal with more than ca. 500 members, and will only keep a few fields about each member, so I don't see scaling being an issue. And as this app may need to be run locally as well, it's easier to make it run on various machines if things are kept as simple as possible.
So the options are to set up a mysql db, or to simply pickle to a file. I would prefer the 2nd, but would like to know if this is a terrible idea.
No, if you can keep all the data in memory a database is not necessary, and just pickling everything could work.
Notable drawbacks with pickling is that it is not secure, somebody can replace your data with something else including executable code and that it's Python-only. With a database you also typically update the data and write to disk at the same time, while you will have to remember to pickle the data and save it to disk. Since this takes time, as you write all the data at once, it's usually done only when you exit, so crashes mean you lose all your changes.
There is a middle-ground though: sqlite. It's a lightwieght, simple SQL database included in Python (since Python 2.5) so you don't have to install any extra software to use it. It is often a quick solution. Since SQLAlcehmey has SQLite support it also means you can even use SQLAlchemy with SQLite as default database, and hence provide an "upgrade path" to more serious databases.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With