Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Using Databases in Python Meet Peewee Create Table

Sam Dale
Sam Dale
6,136 Points

Peewee vs Pickle

Hi there. Something I'm a little confused about is the importance of peewee in Python. When I wanted to store an object in the past, I would write to a file using the pickle library. I'm guessing using SQLite is important for security or using data on the web, but I'm not really seeing why the peewee library is better than the pickle library especially when with peewee you have to go through the extra layer of using sqlite. Is there a clear reason why peewee is superior to pickle? Thanks!

1 Answer

Pickle isn't really a way of storing an 'object' as such, or even data, it's used to serialise an object, such that it can be represented as a string, and then used to later reconstruct that object.

Peewee is an ORM (Object-relational mapping) that just uses Python to store data in a database and allow you to manipulate that data using Python, rather than with SQL or other query language.

It's generally much faster to read and write from a database, even using an ORM in between, than it would be to read and write to files. And databases can have proper relationships between tables, etc.

Not sure if that's made anything clearer. Kenneth Love, did you want to add to this?