Skip to content

bulbs #

Find similar titles

4회 업데이트 됨.

Edit
  • 최초 작성자
    Sardor
  • 최근 업데이트
    JehongLee

Structured data

Category
Programming
Database

Introduction #

Bulbs is an open-source Python persistence framework for graph databases and the first piece of a larger Web-development toolkit that will be released in the upcoming weeks.

It’s like an ORM for graphs, but instead of SQL, you use the graph-traveral language Gremlin to query the database.

Bulbs supports pluggable backends, and we can use it to connect to Neo4j Server.

How to install #

Make sure you have installed Neo4j server on your local machine or to have an access to remote Neo4j server.

Bulbs is a Python library, and the source code is on GitHub at https://github.com/espeed/bulbs.

You can use pip to install the latest version from GitHub into your project’s virtual environment:

$ mkdir example
$ cd example
$ virtualenv env
$ source env/bin/activate
(env)$ pip install https://github.com/espeed/bulbs/tarball/master

Or you can use pip to install a potentially slightly older version from PyPi:

$ mkdir example
$ cd example
$ virtualenv env
$ source env/bin/activate
(env)$ pip install bulbs

Example #

Simple example with relations.

from bulbs.model import Node, Relationship
from bulbs.property import String, Integer, DateTime
from bulbs.utils import current_datetime

class Person(Node):

    element_type = "person"

    name = String(nullable=False)
    age = Integer()


class Knows(Relationship):

    label = "knows"

    created = DateTime(default=current_datetime, nullable=False)

More complex example.

from bulbs.config import Config
from bulbs.gremlin import Gremlin
from bulbs.model import Node, NodeProxy
from bulbs.property import String, Integer
from bulbs.element import Vertex, VertexProxy, EdgeProxy, Edge
from bulbs.neo4jserver import Neo4jResource, NEO4J_URI, \
   VertexIndexProxy, EdgeIndexProxy, ExactIndex

class Person(Node):

    element_type = "person"

    name = String(nullable=False)
    age = Integer()

class Whybase(object):

    def __init__(self):
        self.config = Config(NEO4J_URI)
        self.resource = Neo4jResource(self.config)

        self.gremlin = Gremlin(self.resource)

        self.indicesV = VertexIndexProxy(ExactIndex,self.resource)
        self.indicesE = EdgeIndexProxy(ExactIndex,self.resource)

        self.vertices = VertexProxy(Vertex,self.resource)
        self.vertices.index = self.indicesV.get_or_create("vertices")

        self.edges = EdgeProxy(Edge,self.resource)
        self.edges.index = self.indicesE.get_or_create("edges")

        self.people = NodeProxy(Person,self.resource)
        self.people.index = self.indicesV.get_or_create("person")

whybase = Whybase()
james = whybase.people.create(name="James Thornton",age=34)

print james.eid, james.name, james.age

james.name = "James William Thornton"
james.city = "Dallas"
james.save()

print james.eid, james.name, james.age, james.city

References #

1 http://bulbflow.com

2 https://github.com/espeed/bulbs/

Suggested Pages #

0.0.1_20230725_7_v68