mini-db
A little speaker making a very loud noise: small in size, big in decibels (dB), hence the name.
A small but real relational database in pure Python 3.14, with no dependencies beyond the standard library. It is built one subsystem at a time in the accompanying book, Build Your Own Relational Database in Python.
The code is meant to be read: each chapter adds a feature (or tears down a simplified version and rebuilds it properly) and explains why the simple version wasn't enough.
Status
The book is complete and the code follows it chapter by chapter, through all fifteen chapters and the appendices.
| Chapter | Topic |
|---|---|
| 1 | The relational model |
| 2 | Tables and CRUD |
| 3 | Types and normalization |
| 4 | Constraints |
| 5 | Keys and indexes |
| 6 | Referential integrity |
| 7 | Query primitives |
| 8–9 | Unit of Work (transactions) |
| 10–12 | Concurrency and isolation |
| 13 | Persistence |
| 14 | Query planning |
| 15 | B-trees |
| A | SQL front end |
Installation
Requires Python 3.14 or later. The distribution is called minidb-book; the package you import is minidb.
pip install minidb-book
# or
uv add minidb-book
To work on the code or follow the book, clone the repository and use uv:
git clone git@github.com:stefano-bragaglia/mini-db-book.git
cd mini-db-book
uv sync
A taste
from minidb import Column, Database, ForeignKey, Integer, Numeric, Text
from minidb.operators import Count, Sum
db = Database()
db.create_table("users", [Column("id", Integer()), Column("name", Text()), Column("city", Text())], primary_key="id")
db.create_table(
"orders",
[Column("id", Integer()), Column("user_id", Integer()), Column("total", Numeric(8, 2))],
primary_key="id",
foreign_keys=[ForeignKey("user_id", "users")],
)
db.insert("users", {"id": 1, "name": "Ada", "city": "London"})
db.insert("orders", {"id": 10, "user_id": 1, "total": "25.00"})
db.insert("orders", {"id": 11, "user_id": 1, "total": "15.50"})
report = (
db.query("users", "u")
.join("orders", on=lambda r: r["u.id"] == r["o.user_id"], alias="o")
.where(lambda r: r["u.city"] == "London")
.group_by("u.name", total=Sum("o.total"), n=Count())
)
print(report.all()) # [{'u.name': 'Ada', 'total': Decimal('40.50'), 'n': 2}]
db.insert("orders", {"id": 12, "user_id": 99, "total": "1.00"}) # raises ForeignKeyError
Examples
examples/ holds runnable scripts that reproduce the book's sessions, for example:
uv run python examples/transfers.py
uv run python examples/index_speed.py
examples/toy.py is the list-of-dicts relational algebra toy from Chapter 1 (it is not part of minidb).
Project layout
src/minidb/
database.py Database façade: tables, constraints, foreign keys
table.py Tables, rows and rowids
schema.py Columns, table schemas, CHECK and foreign-key definitions
types.py Column types: Integer, Text, Numeric, Date, ...
normalizers.py Value normalizers applied on write
values.py Value and row type aliases
changes.py Planning of writes into validated changes
index.py Secondary indexes
btree.py B+ tree and the index built on it
query.py Fluent query builder
expr.py Expressions
operators.py Query operators (scan, filter, join, sort, aggregate)
planner.py Query planner
uow.py Unit of Work (transactions)
locks.py Readers-writer locks
storage.py Write-ahead log, snapshots, recovery
sql.py SQL front end
errors.py Error hierarchy
docs/minidb-book/ The book, one Markdown file per chapter
examples/ Runnable scripts
tests/ Tests
The book
Start at the index and read the chapters in order, since each builds on the previous one's code. Every chapter ends with exercises, and Appendix D answers them.
Development
The code is linted and formatted with ruff (all rules enabled) and uses PEP 695 generics and protocols throughout.
uv run ruff check
uv run ruff format
uv run python -m examples.run_tests
License
- Code (
src/,examples/,tests/): MIT License. - Book (
docs/minidb-book/): Creative Commons Attribution 4.0 (CC BY 4.0).
Copyright (c) 2026 Stefano Bragaglia.
Metadata
Release files for minidb-book 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| minidb_book-0.1.0.tar.gz | 61.6 kB | Without provenance | Details for minidb_book-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| minidb_book-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for minidb_book-0.1.0-py3-none-any.whl |
Total release size: 131.5 kB
Release files / minidb_book-0.1.0.tar.gz
| Download URL | minidb_book-0.1.0.tar.gz |
|---|---|
| Size | 61.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
65eaa120e658316dc0ed1510a3acdf373e102509213dded9ea6ce63e1aa5448f
|
|
BLAKE2b-256 checksum How to use checksums |
7990c3ac3c553cf2b8688034df23e8741644962c71175deac829329a936f883e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / minidb_book-0.1.0-py3-none-any.whl
| Download URL | minidb_book-0.1.0-py3-none-any.whl |
|---|---|
| Size | 69.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1f190fa7572a322230d3629e98ee2441c0ad23dd21aaeb4063b77452713f3815
|
|
BLAKE2b-256 checksum How to use checksums |
59277dd57b6a698b66550d8062280f01d46fd941869fc3d23ddd140b95823e4c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for minidb-book 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.