Skip to main content

PyGraphDB

An educational graph database library built from scratch in Python. Part of the PyLearn educational platform for kids aged 12+.

A graph database stores data as nodes (entities) and edges (relationships) -- like a social network map where people are dots and friendships are lines connecting them.

Features

  • Nodes & Edges -- Create entities with labels and properties, connect them with typed relationships
  • CRUD Operations -- Add, get, update, and delete nodes and edges
  • Graph Traversal -- Explore your graph with BFS (breadth-first) and DFS (depth-first) algorithms
  • Shortest Path -- Find the quickest route between two nodes (like GPS directions)
  • Pattern Matching -- Search for nodes and edges by label, type, or properties
  • Cypher-like Queries -- Ask questions with a simple query language inspired by Neo4j's Cypher
  • Persistence -- Save and load your graph to/from JSON files
  • Neighbor & Degree -- Find connected nodes and count connections

Quick Start

from pygraphdb import Graph, bfs, shortest_path, execute_query, find_nodes

# Create a social network
g = Graph()
g.add_node("alice", label="Person", properties={"name": "Alice", "age": 13})
g.add_node("bob", label="Person", properties={"name": "Bob", "age": 14})
g.add_node("charlie", label="Person", properties={"name": "Charlie", "age": 13})

g.add_edge("e1", "alice", "bob", rel_type="KNOWS")
g.add_edge("e2", "bob", "charlie", rel_type="KNOWS")

# Find Alice's friends
friends = g.get_neighbors("alice", direction="outgoing")
print([f.properties["name"] for f in friends])  # ['Bob']

# Traverse the whole network
visited = bfs(g, "alice")
print([n.properties["name"] for n in visited])  # ['Alice', 'Bob', 'Charlie']

# Find shortest path
path = shortest_path(g, "alice", "charlie")
print([n.properties["name"] for n in path])  # ['Alice', 'Bob', 'Charlie']

# Query with Cypher-like syntax
results = execute_query(g, 'MATCH (n:Person) WHERE n.name = "Alice" RETURN n')
print(results[0].properties["name"])  # 'Alice'

# Pattern matching
teenagers = find_nodes(g, label="Person")
print(len(teenagers))  # 3

Installation

# Clone and install
git clone https://github.com/robcox2910/pygraphdb.git
cd pygraphdb
uv sync --all-extras

# Run tests
uv run pytest

# Lint & type check
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/pygraphdb/

Metadata

Release files for fromscratch-pygraphdb 0.4.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-pygraphdb 0.4.0
File Size Uploaded Provenance
fromscratch_pygraphdb-0.4.0.tar.gz 92.4 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for fromscratch-pygraphdb 0.4.0
File Interpreter ABI Platform
fromscratch_pygraphdb-0.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 117.0 kB

Release files / fromscratch_pygraphdb-0.4.0.tar.gz

Download URL fromscratch_pygraphdb-0.4.0.tar.gz
Size 92.4 kB
Tags Source
SHA-256 checksum
How to use checksums
ada5b17f72a8cc7ec3674e8ed933cc31c5fd5f855cba483029c99e44e66ba894
BLAKE2b-256 checksum
How to use checksums
6ad0ddebba1f02b48f7ddd9bf1112ced52af59a54c6d7a4aa0c42e6605db1ddd
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_pygraphdb-0.4.0-py3-none-any.whl

Download URL fromscratch_pygraphdb-0.4.0-py3-none-any.whl
Size 24.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a0df8aeb79cb36bf041c203580079eac0e67de43bf0c01f9f6fbd5e2b4b24ed2
BLAKE2b-256 checksum
How to use checksums
9c9863471e227b2271591f39de0a0338f34a1ebe8ee037dd56fe09b17f1fad8e
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-pygraphdb 0.4.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_pygraphdb-0.4.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.4.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