API Reference

Peewee

A small, expressive ORM for Python supporting SQLite, PostgreSQL, and MySQL with a concise query API.

Official Documentation ↗
CompatibilityThis documentation covers version v4.5.3. Check the official docs for the latest API surface.

Installation

pippip install peewee

Methods

Peewee maps Python classes to tables and builds SQL from model fields and query expressions.

Key Features

  • Small footprint with a clean model API
  • Multiple SQL backends including SQLite
  • Query expressions and transactions

Usage Notes

Pin a version and check the official docs for the API surface you depend on before upgrading.

Errors

The official API reference declares the following error types:

API reference evidence

Fetched from official sources on 2026-11-08T16:03:08.4363995+08:00 via WebFetch 官方 API 页面(Model / Database / exceptions 章节).

FAQ

How do I create the tables?
Call db.create_tables([User]) after defining models, or use playhouse.migrate for schema changes.
How are transactions handled?
Use with db.atomic(): to group writes; the block commits on success and rolls back on exception.
Does it support async?
Not natively. Peewee is synchronous; run it in a thread for async apps, or use a different ORM for asyncio.