DEV Community

MrRobot
MrRobot

Posted on

Peewee - A Lightweight ORM for Python

Peewee is a small, expressive Object Relational Mapper (ORM) for Python that provides a simple and efficient way to interact with databases. It supports SQLite, MySQL, and PostgreSQL out of the box. Peewee lets you define database models as Python classes and perform queries using Pythonic syntax, making database management much easier and cleaner. It’s perfect for small to medium projects where you need database functionality without the overhead of larger ORMs like SQLAlchemy or Django ORM.


Installation:

pip install peewee
Enter fullscreen mode Exit fullscreen mode

Example usage:

from peewee import *

db = SqliteDatabase("people.db")

class Person(Model):
    name = CharField()
    age = IntegerField()

    class Meta:
        database = db

db.connect()
db.create_tables([Person])

Person.create(name="Alice", age=25)
for person in Person.select():
    print(person.name, person.age)
Enter fullscreen mode Exit fullscreen mode

PyPI page: https://pypi.org/project/peewee/
GitHub page: https://github.com/coleifer/peewee


3 Project Ideas:

  1. Build a personal expense tracker with a local SQLite database.
  2. Create a desktop app for managing contacts or inventory.
  3. Develop a lightweight blog or notes app with user authentication.

Top comments (0)