Table of Contents
These days, I have been dabbling into Database Management using Python. Today’s post is a short discussion on a ORM I discovered, and some resources which I found very useful for Peewee.
What is an ORM
An ORM (Object Relational Mapper) is a library that automates the transfer of data stored in relational database tables into objects that are more commonly used in application code.

ORMs are very useful since they provide high level abstraction of a database, and allows us to write Python code to do CRUD operations on a database instead of writing SQL.The ability to write Python code to manipulate the database instead of writing SQL speeds up the development process significantly. There are many ORMs for Python, like SQLAlchemy, Storm, SQLObject, etc
Why Peewee
Well, the learning curve for Peewee is easier, especially when one is new to database management using Python in general. Peewee can be learned easily than SQLAlchemy and other ORMs. Peewee also works with many web frameworks. Also, it supports all the common relational database backends, that is PostgreSQL, MySQL or SQLite for that matter.
Useful Resources for Peewee
Here are some resources that I recommend and are absolutely worth a read if you are interested in learning more about Peewee.
-
The official Peewee quickstart documentation
gives you a head start on Peewee. -
An encrypted command-line diary with Python
is an awesome walkthrough explaining how to use SQLite, SQLCipher and Peewee to create an encrypted file with your contents, diary or otherwise. -
An Intro to Peewee – Another Python ORM
is a short tutorial that walks through creating a database model mapping, adding data, deleting records and querying fields. -
Introduction to peewee
uses an example public dataset, loads it into a SQLite database and shows how to query it using Peewee. -
Shortcomings in the Django ORM and a look at Peewee
from the author of the Peewee ORM explains how some of the design decisions made in Peewee were in reaction to parts of the Django ORM that didn’t work so well in practice. -
Flask and Peewee 101
has some basic code for querying with Peewee and populating a drop-down in a Jinja2 template. Note that the Flask-peewee extension is no longer maintained, although you do not need to use it to work with both Flask and Peewee in an application. -
How to make a Flask blog in one hour or less
is a well written tutorial that uses the Peewee ORM instead of SQLAlchemy for the blog back end. -
These posts on querying the top item by group with Peewee ORM
andquerying the top N objects per group with Peewee ORM
provide working examples on how to properly query your data via Peewee. -
There was a good discussion in a Python subreddit
thread about the differences between Peewee and SQLAlchemy. Charles Leifer even chimed in to add his own fair assessment of the differences in the ORMs.
That’s it for this post, see you in the next one!