Skip to content

What is PookieDB?

You have built a form that collects patient data and stores it in a Python list. It works — but every time you stop the app, the list disappears. Restart it and you are back to zero.

The fix is a database — somewhere to save data permanently so it survives restarts.


What is a database?

A database is a file that holds your data in a structured, organised way. You save something to it, stop your program, start it again tomorrow, and the data is still there.

For now you will use SQLite — a database that lives as a single .sqlite3 file right inside your project folder. No setup, no server, nothing to install separately. It just works.


What is PookieDB?

PookieDB is a Python library that lets you talk to a database using plain Python — no SQL required.

Instead of writing database commands like INSERT INTO patients VALUES (...), you just write Python:

Patient.objects.create(name="Alice", age=24)

PookieDB translates that into the right database command for you behind the scenes.

This idea — using Python classes to represent database tables — is called an ORM (Object Relational Mapper). You write Python. PookieDB handles the database.


Installing PookieDB

Make sure your virtual environment is active ((.venv) showing in the terminal), then run:

pip install pookiedb

Connecting to SQLite

Before you can do anything with PookieDB, you connect it to a database file:

import pookiedb

pookiedb.connect("sqlite:///mydb.sqlite3")

That one line creates (or opens) a file called mydb.sqlite3 in your project folder. If the file does not exist yet, PookieDB creates it. If it already exists, PookieDB opens it and all your previous data is still there.

The sqlite:/// part tells PookieDB you are using SQLite. The mydb.sqlite3 is the filename — you can name it whatever you like.


Challenge

In your project folder, create a new file called database.py. Add the two lines above — the import and the connect call. Run it with python database.py. Then look in your project folder — do you see a .sqlite3 file appear?


← The Patient Form    Next: Defining Your First Table →