skip to navigation
skip to content

Not Logged In

kenji 0.3.1

simple sqlite-backed graph datastore

Deprecated in favour of `graphlite`_.

An embedded social graph datastore with an SQLite3 backend.

Kenji was inspired by both Neomodel and Flockdb, taking the best out of both worlds and putting it into a smaller scale library.

Supported Python versions include python 2.6+, 3.3+, as well as pypy. Works great with gevent too.

Synopsis

Relations, simplified- Kenji stores property-less relations between your data. Let your document/key-value/relational datastore store all your other documents. Because of the specific problems it aims to solve, Kenji’s codebase is tiny, just like the apps it’s meant for. To install, just:

$ pip install kenji

Or check out how to install pip and then install the correct package if you’re on Windows. Then initialize a graph, and play around with it.

from kenji import Graph, V
g = Graph(graphs=['knows'])

g.store(V(2).knows(1))
for i in range(2, 5):
    g.store(V(1).knows(i))

Let’s see what kind of queries can we make against the data we’ve stored in the DB:

assert g.exists(V(1).knows(2))
assert list(g.select(V(1).knows)) == [2,3,4]
assert g.select(V().knows(1)).first == 2

What about asking questions like who are the people that 1’s friends know?

assert list(g.select(V(1).knows)
              .traverse('knows')) == [1]

We can also bundle up changes in a transaction, because kenji is based on an RDBMS backend:

with graph.transaction() as tr:
    tr.store(V(1).knows(3))
    tr.delete(V(1).knows(2))

FAQ

1. Is Kenji thread-safe? Kenji is thread safe, as long as you use it with the constraints of the SQLite library. According to the SQLite docs, threads are evil.

2. What about transactions? Currently there is no guaranteed method of making atomic transactions thread-safe, primarily because they aren’t thread safe in the SQLite3 library as well. We can sacrifice atomicity for thread safety but then again, that means that you won’t really have a transaction.

3. Is Kenji a property graph? No, it is merely a social graph. If you need properties in edges between nodes then you should consider other graphs like Neo4j.

 
File Type Py Version Uploaded on Size
kenji-0.3.1.tar.gz (md5) Source 2014-08-03 8KB
  • Downloads (All Versions):
  • 1 downloads in the last day
  • 50 downloads in the last week
  • 247 downloads in the last month