Documentation

Overview

CogDB is a persistent, in-process graph database written entirely in Python. It is designed to be easy to use, require no external setup, and fit naturally into Python applications.

There is no server to run and no infrastructure to manage. You simply import it into your Python application. CogDB also works well in interactive environments such as Jupyter notebooks.

Querying Graphs

Instead of a standalone query language, CogDB provides a Python-native query system called Torque. If you're comfortable writing Python, you can start querying graphs right away.

from cog.torque import Graph

g = Graph("social")
g.put("alice", "follows", "bob")
g.put("bob", "follows", "charlie")

g.v("alice").out("follows").all()  # → {'result': [{'id': 'bob'}]}

Data Storage

CogDB has a built-in storage engine and stores data as triples. It models data as:

Node → Edge → Node
(e.g., Alice → Follows → Bob)

Key-value pairs let you store facts; triples let you store relationships. With a source, a destination, and a label, you get the expressive power of a graph with only one step more structure than a key-value store.

Ideal Use Cases

CogDB is a good fit when you want persistent graph storage with minimal overhead, for example:

  • Research, prototyping, and exploratory work
  • Interactive analysis in Python notebooks (Jupyter, Colab, etc.)
  • Scripts or small to medium-sized services that need graph traversal without running a heavyweight graph database
  • Knowledge graphs and semantic search applications
  • Running in the browser via Pyodide

Because CogDB is a pure Python library, it can be imported anywhere you would normally write Python code.

Guide

On this page