Skip to main content

PyDocDB

An educational document store (like MongoDB) built from scratch in Python. Part of the PyLearn platform for kids aged 12+.

PyDocDB stores JSON-like documents without requiring a fixed schema -- each document can have different fields, just like how every index card in a filing cabinet can have different information on it.

Features

  • Documents -- Dict-like objects with auto-generated unique IDs
  • Collections -- Named groups of documents with full CRUD operations
  • Query Language -- Filter with operators: $eq, $gt, $lt, $gte, $lte, $ne, $in, $exists, $and, $or, $not
  • Nested Field Access -- Query nested fields with dot notation (e.g., "address.city")
  • Projection -- Return only specific fields from documents
  • Indexing -- Create indexes on fields for faster lookups
  • Persistence -- Save/load collections to JSON files on disk
  • Aggregation -- Pipeline with $match, $group, $sort, $limit, $count

Quick Start

from pydocdb import Collection, save_collection, load_collection, aggregate

# Create a collection (like labeling a new folder in a filing cabinet)
students = Collection("students")

# Insert documents (like filing index cards)
students.insert_one({"name": "Alice", "age": 14, "grade": "9th"})
students.insert_one({"name": "Bob", "age": 13, "hobby": "chess"})
students.insert_one({"name": "Charlie", "age": 15, "grade": "10th"})

# Find documents with queries
teenagers = students.find({"age": {"$gte": 13}})
alice = students.find_one({"name": "Alice"})

# Update and delete
students.update_one({"name": "Alice"}, {"age": 15})
students.delete_one({"name": "Bob"})

# Use projection to get only specific fields
names = students.find({}, projection={"name": 1, "_id": 0})

# Aggregate data
result = aggregate(students.to_list(), [
    {"$group": {"_id": "$grade", "count": {"$sum": 1}}},
    {"$sort": {"count": -1}},
])

# Save to disk and load later
save_collection(students, "students.json")
loaded = load_collection("students.json")

Installation

uv add pydocdb

Development

git clone https://github.com/robcox2910/pydoc-db.git
cd pydoc-db
uv sync --all-extras
uv run pytest
uv run ruff check src/ tests/
uv run pyright src tests

Releasing

Other projects in the series (PyStack) use a pinned release of this one, not whatever is on main. To publish a change for them:

  1. Merge the change to main.
  2. Tag it: git tag -a vX.Y.Z -m vX.Y.Z && git push origin vX.Y.Z. A change to the public API bumps the minor version (v0.1.0 → v0.2.0); anything else bumps the patch (v0.1.0 → v0.1.1).
  3. In each project that uses it, edit the tag in [tool.uv.sources], run uv lock --upgrade-package <name>, and open a pull request so CI checks the pair together.

This project is one of a series that builds real systems "from scratch in Python" to teach how they work. See the series home for the full story.

Project What it teaches Repository Docs
PyOS Operating systems py-os Docs
Pebble Compilers and programming languages pebble-lang Docs
PyDB Relational databases pydb Docs
PyKV Key-value stores pykv Docs
PyDocDB Document databases pydoc-db Docs
PyGraphDB Graph databases pygraphdb Docs
PyTSDB Time-series databases pytsdb Docs
PyVecDB Vector databases pyvecdb Docs
PyColDB Column-family databases pycoldb Docs
PyCrypt Cryptography pycrypt Docs
PyNet Computer networking pynet Docs
PyWeb HTTP web servers pyweb Docs
PyGit Version control pygit Docs
PySearch Search engines pysearch Docs
PyMQ Message queues pymq Docs
PyLLM Language models (the brain) pyllm Docs
PyScheduler Job scheduling pyscheduler Docs
PyStack Full-stack integration pystack Docs

Documentation

Full docs (with kid-friendly explanations of every idea): https://robcox2910.github.io/pydoc-db/

Metadata

Release files for fromscratch-pydocdb 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fromscratch-pydocdb 0.3.0
File Size Uploaded Provenance
fromscratch_pydocdb-0.3.0.tar.gz 93.9 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for fromscratch-pydocdb 0.3.0
File Interpreter ABI Platform
fromscratch_pydocdb-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 119.3 kB

Release files / fromscratch_pydocdb-0.3.0.tar.gz

Download URL fromscratch_pydocdb-0.3.0.tar.gz
Size 93.9 kB
Tags Source
SHA-256 checksum
How to use checksums
3e1abeda7caff9a2e7e18deedb0687c1fd6c45f5a81738bf0d8b6709aab597c0
BLAKE2b-256 checksum
How to use checksums
fbf03fbf555f8ae0dc9bfe38c10cd5b84a3f0ad4a55232c98be67e94c5525f94
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.

Transparency log

Release files / fromscratch_pydocdb-0.3.0-py3-none-any.whl

Download URL fromscratch_pydocdb-0.3.0-py3-none-any.whl
Size 25.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
27c7c349b8989b629c48e75dd6b229e02c22b36329f705067a6353f8234ff794
BLAKE2b-256 checksum
How to use checksums
732ba716cc871f4916170534707af792572a03d3700526651322bdf72e718616
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.

Transparency log

Security for fromscratch-pydocdb 0.3.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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for fromscratch_pydocdb-0.3.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.

Transparency log

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.

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page