# Quick Start Guide

CogDB is a persistent, embedded graph database library implemented purely in Python. Torque is CogDB's graph query language, it is implemented as a Python API. CogDB is an ideal choice if you need a database that is easy to use, that has no setup overhead and (curretly limited to) low workloads. As a Python library, CogDB can be imported into any Python application, such as a Flask (opens new window) application. CogDB can also be used interactively in an IPython environment like Jupyter notebooks.

CogDB is a Triplestore. Unlike relational databases or key value stores, it models data as triples. Triples are the atomic form of data stored in CogDB. To make these triples more meaningful, they can be thought of as subject predicate object combinations. Although it is not strictly necessary, making your data into meaningful combinations of triples would make the graph structure formed from your data meaningful to query and reason about.

In general, triples are a serialization format for RDF databases (See Wikipedia (opens new window), W3C (opens new window) for details) and generally graph databases that model graphs this way are known as RDF databases. CogDB is inspired by RDF databases, but it does not follow a strict RDF format. It allows you to store any kind of (texutal) data in a graph and query it using Torque.

# Installing Cog

pip install cogdb

In short, an N-Triple is sequence of subject, predicate and object in a single line that defines a connection between two vertices:

vertex <predicate> vertex

Learn more about RDF triples (opens new window)

# Creating a graph

from cog.torque import Graph
g = Graph("people")
g.put("alice","follows","bob")
g.put("bob","follows","fred")
g.put("bob","status","cool_person")
g.put("charlie","follows","bob")
g.put("charlie","follows","dani")
g.put("dani","follows","bob")
g.put("dani","follows","greg")
g.put("dani","status","cool_person")
g.put("emily","follows","fred")
g.put("fred","follows","greg")
g.put("greg","status","cool_person")
g.put("bob","score","5")
g.put("greg","score","10")
g.put("alice","score","7")
g.put("dani","score","100")

# Everyone with status 'cool_person'

g.v().has("status", 'cool_person').all()

# Visualize a graph query result

g.v().tag("from").out("follows").tag("to").view("follows").url

The query above will return a path to an HTML file which you can view in a browser

# Try this example online in the Playground

CogDB instance in the Playground is loaded with a sample dataset.