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 --versionOutput 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 --versionIf 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-projectCreate the virtual environment.
python -m venv venvActivate it.
On Windows:
venv\Scripts\activateOn macOS/Linux:
source venv/bin/activateYour prompt now shows (venv). This means it works.
Step 2: Install Peewee with pip
Now install Peewee. Use pip install.
pip install peeweeWait for the download. It finishes in seconds.
You can also install a specific version.
pip install peewee==3.17.0Check the latest version on the Peewee official site.
Step 3: Verify the Installation
Open Python in your terminal.
pythonThen import Peewee.
import peewee
print(peewee.__version__)3.17.0No 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.pyAlice is 30 years oldIt 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 pymysqlFor PostgreSQL use psycopg2.
pip install psycopg2-binaryThen 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 peeweeOn 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 peeweeCheck your version after upgrade.
import peewee
print(peewee.__version__)Uninstall Peewee
To remove Peewee.
pip uninstall peeweeConfirm 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.txtLater install from that file.
pip install -r requirements.txtThis 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.