Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Introducing Bulbs for Python

DZone's Guide to

Introducing Bulbs for Python

· Web Dev Zone
Free Resource

Try RAD Studio for FREE!  It’s the fastest way to develop cross-platform Native Apps with flexible Cloud services and broad IoT connectivity. Start Your Trial Today!

In the process of developing Whybase, a startup debuting this fall,  developer James Thornton needed a persistence layer to model Whybase's complex relationships, and from that need came Bulbs, the open-sourced version of said framework.

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.

-- James Thornton

Essentially, this allows you to take your code anywhere, since you no longer have to worry about vendor lock in.

Thornton provides a couple code examples on how to model and create domain objects:

Model Domain Objects

from bulbs.model import Node
from bulbs.datatype import Property, String
        
class Idea(Node):

    element_type = "idea"

    text = Property(String, nullable=False)
    stub = Property(String,"make_stub")

    def make_stub(self):
        return utils.create_stub(self.text)
           
    def after_created(self):
        Relationship.create(self,"created_by",current_user)


Create Domain Objects

>>> from whybase.idea import Idea
>>> idea = Idea(text="the key to life is perspective")
>>> idea.eid
>>> 8
>>> idea.text
'the key to life is perspetive'
>>> idea.stub
'the-key-to-life-is-perspective'


There's even this cool video by Gremlin creator, Marko Rodriguez:




So why take the time to create these graphs?  As Thornton puts it:

Graphs are a much more elegant way of storing relational data. Graphs are a fundamental data structure in computer science, and with graph databases you don’t have to mess with tables or joins – everything is explicitly joined.

--James Thornton


Bulbs is currently available for download here, and as previously mentioned, this is just the beginning of a much larger Web-Development toolkit that will be here soon.

Get Your Apps to Customers 5X Faster with RAD Studio. Brought to you in partnership with Embarcadero.

Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}