Last modified: Jun 10, 2026

Install Peewee ORM in Python

Peewee is a lightweight and expressive ORM for Python. It makes database work simple. You can use it with SQLite, MySQL, and PostgreSQL.

This guide shows you how to install Peewee ORM in Python. We cover all steps. You will have it running in minutes.

Let's start from scratch. No prior knowledge needed.

What is Peewee ORM?

Peewee is a small ORM. ORM stands for Object-Relational Mapping. It maps Python classes to database tables.

You write Python code instead of SQL. Peewee handles the rest. It is fast and easy to learn.

Many developers prefer it for small to medium projects. It is perfect for beginners.

Prerequisites

You need Python installed. Check your version.

python --version

Output should be Python 3.6 or higher. Peewee works with Python 3 only.

You also need pip. Pip is Python's package manager. It comes with modern Python.

pip --version

If you see a version number, you are ready.

Step 1: Create a Virtual Environment

A virtual environment keeps dependencies separate. It avoids conflicts.

Open your terminal or command prompt. Navigate to your project folder.

mkdir my-peewee-project
cd my-peewee-project

Create the virtual environment.

python -m venv venv

Activate it.

On Windows:

venv\Scripts\activate

On macOS/Linux:

source venv/bin/activate

Your prompt now shows (venv). This means it works.

Step 2: Install Peewee with pip

Now install Peewee. Use pip install.

pip install peewee

Wait for the download. It finishes in seconds.

You can also install a specific version.

pip install peewee==3.17.0

Check the latest version on the Peewee official site.

Step 3: Verify the Installation

Open Python in your terminal.

python

Then import Peewee.

import peewee
print(peewee.__version__)
3.17.0

No error means success. You installed Peewee ORM in Python.

Step 4: Create a Simple Database

Let's test with SQLite. SQLite needs no extra setup.

Create a file named test_db.py.

from peewee import SqliteDatabase, Model, CharField, IntegerField

# Connect to SQLite database
db = SqliteDatabase('my_app.db')

# Define a model
class User(Model):
    name = CharField()
    age = IntegerField()

    class Meta:
        database = db

# Connect and create table
db.connect()
db.create_tables([User])

# Insert a record
user = User(name='Alice', age=30)
user.save()

# Query all users
for u in User.select():
    print(f'{u.name} is {u.age} years old')

db.close()

Run the script.

python test_db.py
Alice is 30 years old

It works. You just used Peewee ORM in Python.

Step 5: Install Database Drivers

For MySQL or PostgreSQL, install drivers.

For MySQL use pymysql or mysql-connector-python.

pip install pymysql

For PostgreSQL use psycopg2.

pip install psycopg2-binary

Then connect Peewee to these databases.

from peewee import MySQLDatabase, PostgresqlDatabase

# MySQL example
mysql_db = MySQLDatabase('my_db', user='root', password='pass', host='localhost', port=3306)

# PostgreSQL example
pg_db = PostgresqlDatabase('my_db', user='postgres', password='pass', host='localhost', port=5432)

Use the same model approach. Peewee works the same across databases.

Common Installation Issues

Sometimes pip fails. Check your internet connection.

If you see permission errors, use --user flag.

pip install --user peewee

On Linux, you might need sudo. But virtual environments avoid this.

For Windows, ensure Python is in PATH. Reinstall Python if needed.

Upgrade Peewee

Keep Peewee updated.

pip install --upgrade peewee

Check your version after upgrade.

import peewee
print(peewee.__version__)

Uninstall Peewee

To remove Peewee.

pip uninstall peewee

Confirm with y. It is gone.

Best Practices

Always use virtual environments. It keeps your projects clean.

Pin your Peewee version in requirements.txt.

pip freeze > requirements.txt

Later install from that file.

pip install -r requirements.txt

This ensures consistent setups.

Conclusion

You now know how to install Peewee ORM in Python. It is simple and fast.

We covered virtual environments, pip installation, and database setup. You tested with SQLite.

Peewee is great for beginners. It is also powerful for real projects.

Start building your database apps today. Use Peewee to write clean Python code.

Remember to keep learning. Try more features like migrations and joins.