Giter Club home page Giter Club logo

gizmo's Introduction

Gizmo

Alpha build of this library. The API may change while working toward a stable release

Gizmo is a lightweight asynchronous Python 3.5+ Object Graph Mapper (O.G.M.) for the Tinkerpop Rexster graphs.

About

Gizmo starts and ends with Gremlin/Groovy. It is made up of entity, mapper, query, request, response, and other objects whose job is to convert pure Python to a Gremlin/Groovy string to be executed on a server.

QuickStart Example

    import asyncio

    from gizmo import Request, Vertex, Edge, Mapper, String

    from gremlinpy import Gremlin


    # setup the connection
    req = Request('localhost', 8182)
    gremlin = Gremlin('g') # this should be whatever your graph name is
    mapper = Mapper(request=req, gremlin=gremlin)


    # define a few entity classes
    class User(Vertex):
        name = String()


    class Knows(Edge):
        pass


    # create a few entities
    mark = User({'name': 'mark'})
    steve = User({'name': 'steve'})
    knows = mapper.connect(mark, steve, Knows)


    # Save your entities
    async def example():
        mapper.save(knows) # saving the edge will save users if they needed

        result = await mapper.send()

        # entities have been updated with response data from the graph
        print('mark: {}'.format(mark['id']))
        print('steve: {}'.format(steve['id']))
        print('knows: {}'.format(knows['id']))


    asyncio.get_event_loop().run_until_complete(example())


    # or write a custom query

    async def custom():
        g = Gremlin()
        g.V()

        result = await mapper.query(gremlin=g)

        print(result) # gizmo.mapper.Collection object
        print(result[0]) # user object (because of the queries in prev example)

    asyncio.get_event_loop().run_until_complete(custom())


    # do whatever Gremlin/Groovy allows you to do

    async def random_java():
        script = 'def x = new Date(); x'

        r = await mapper.query(script=script)

        print(r[0]['response'].value) # whatever x evaluates to

    asyncio.get_event_loop().run_until_complete(random_java())

Running tests

Test can be run via the setup file or directly with python -m.

python setup.py test

or

python -m unittest gizmo.test.entity
python -m unittest gizmo.test.mapper
python -m unittest gizmo.test.integration.tinkerpop
...

If you're going to run the integration tests, right now, both the name of the graph and the port are hard-coded into the suite. Make sure your Gremlin and Titan server use these settings:

tinkerpop

  • graph: gizmo_testing
  • port: 8182

titan

  • graph: gizmo_testing
  • port: 9192

gizmo's People

Contributors

emehrkay avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.