Overview
CogDB is a persistent, embedded 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
Quick Start
Get up and running with CogDB in minutes
Examples
Practical examples and common patterns
Torque API
Complete API reference for graph traversal
JSON Storage
Store and query JSON documents as graphs
Word Embeddings
Vector search and similarity queries
Graph Server
Network access and REST API
Guide: Build a Knowledge Graph from Text
Extract entities from text, build a knowledge graph in Python, and query it with CogDB.