Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there anything wrong with creating a Python Pickle powered website?

I have been toying with this idea for quite awhile now, but haven't seen any information on people doing it. I have a small website project where I need to load and modify 1 object. This object is pretty simple, and shouldn't be more than a few kb. Instead of running a DB for this small amount of data, why not just use pickle and/or shelve to save this data, and load it? I am planning on using a micro web framework like Bottle or Flask for the project.

Are there any reasons to not use this method to load the data? It will only load the pickle file at the time Apache starts up, so I don't think speed will be effected (faster than querying a db).

Thanks for any input!

like image 547
Shane Reustle Avatar asked Sep 10 '10 02:09

Shane Reustle


3 Answers

I wouldn't write a pickled string to a file directly. There are too many low-level details to worry about. Check out Durus, ZODB, or this post from FriendFeed about storing Python objects in MySQL.

Don't discard relational databases, though, they give you a lot of bang right out of the box (even for simple projects).

like image 150
Sean Woods Avatar answered Sep 21 '22 14:09

Sean Woods


There is no reason why you can't implement object persistence via the standard Python pickle or shelve modules. Just make sure your objects are cleanly and securely picklable. Scalability may become a concern if your site grows beyond your current scope, but until then your idea should work just fine. If that day comes, the next obvious step would be to consider using Python's excellent SQLite module that comes pre-packaged with recent versions of the language.

like image 20
Kevin Jacobs Avatar answered Sep 20 '22 14:09

Kevin Jacobs


In addition to the concurrency issues you are already aware of, you also must ensure that the file is always in a consistent state. For example, if the server crashes in the middle of writing the file, what happens then? It's a case you need to consider and implement a solution for if you go this route.

like image 33
Nathan Davis Avatar answered Sep 21 '22 14:09

Nathan Davis