Skip to main content

A queryable object persistence and relationship framework based on the Neo4j graph database.

Project description

A graph based queryable object persistance framework built on top of Neo4j.

Build status

https://secure.travis-ci.org/onefinestay/kaiso.png?branch=master

Example

In addition to objects, Kaiso also stores the class information in the graph. This allows us to use cypher to query instance information, but also to answer questions about our types.

Let’s define some basic classes

from kaiso.attributes import Integer, Outgoing, String, Uuid
from kaiso.types import Entity, Relationship


# define a simple type hierarchy

class Knows(Relationship):
    pass


class Animal(Entity):
    id = Uuid(unique=True)
    name = String()
    knows = Outgoing(Knows)


class Carnivore(Animal):
    pass


class Herbivore(Animal):
    pass


class Penguin(Herbivore):
    favourite_ice_cream = String()


class Lion(Carnivore):
    n_siblings = Integer()

As with any orm, we can make some instances and persist them in our graph

from kaiso.persistence import Manager

manager = Manager("http://localhost:7474/db/data/")


# create some instances

fred = Penguin(name="Fred")
tom = Lion(name="Tom")

relation = Knows(fred, tom)

manager.save(fred)
manager.save(tom)
manager.save(relation)

Using the Neo4j web interface to explore our graph, we find Tom and Fred:

docs/images/instances.png

However, in addition, we can also see the type information in the graph:

docs/images/type_hierarchy.png

We can make use of the type information in our queries, e.g. to find all herbivores who know a carnivore

START
    Herbivore=node:persistabletype(id="Herbivore"),
    Carnivore=node:persistabletype(id="Carnivore")

MATCH
    Carnivore <-[:ISA*]-()<-[:INSTANCEOF]-(carnivore),
    Herbivore <-[:ISA*]-()<-[:INSTANCEOF]-(herbivore),

    (herbivore)-[:KNOWS]->(carnivore)

RETURN
    "The herbivore",
    herbivore.name,
    "knows the carnivore",
    carnivore.name;
==> +---------------------------------------------------------------------+
==> | "The herbivore" | "Fred"      | "knows the carnivore" | "Tom"       |
==> +---------------------------------------------------------------------+

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kaiso-0.14.3.tar.gz (33.1 kB view details)

Uploaded Source

File details

Details for the file kaiso-0.14.3.tar.gz.

File metadata

  • Download URL: kaiso-0.14.3.tar.gz
  • Upload date:
  • Size: 33.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for kaiso-0.14.3.tar.gz
Algorithm Hash digest
SHA256 c972671c30503335c1ab095b2e74b1a0c0f162ae6938aa859cc2c7ee87c3a6ab
MD5 3fa34e54034d84b33f32da0b4def82b7
BLAKE2b-256 0363ee18533c94cabc2ec1ada2e3da08c019b0098e54316e27f8e26656290544

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page