Gremlin

class mogwai.gremlin.base.BaseGremlinMethod(path=None, method_name=None, classmethod=False, property=False, defaults=None, transaction=True, imports=None)

Maps a function in a groovy file to a method on a python class

configure_method(klass, attr_name, gremlin_path)

Sets up the methods internals

Parameters:
  • klass (object) – The class object this function is being added to
  • attr_name (str) – The attribute name this function will be added as
  • gremlin_path (str) – The path to the gremlin file containing method
transform_params_to_database(params)

Takes a dictionary of parameters and recursively translates them into parameters appropriate for sending over Rexpro.

Parameters:params (dict) – The parameters to be sent to the function
Return type:dict
class mogwai.gremlin.base.GremlinMethod(path=None, method_name=None, classmethod=False, property=False, defaults=None, transaction=True, imports=None)

Gremlin method that returns a graph element

configure_method(klass, attr_name, gremlin_path)

Sets up the methods internals

Parameters:
  • klass (object) – The class object this function is being added to
  • attr_name (str) – The attribute name this function will be added as
  • gremlin_path (str) – The path to the gremlin file containing method
transform_params_to_database(params)

Takes a dictionary of parameters and recursively translates them into parameters appropriate for sending over Rexpro.

Parameters:params (dict) – The parameters to be sent to the function
Return type:dict
class mogwai.gremlin.base.GremlinTable(path=None, method_name=None, classmethod=False, property=False, defaults=None, transaction=True, imports=None)

Gremlin method that returns a table as its result

configure_method(klass, attr_name, gremlin_path)

Sets up the methods internals

Parameters:
  • klass (object) – The class object this function is being added to
  • attr_name (str) – The attribute name this function will be added as
  • gremlin_path (str) – The path to the gremlin file containing method
transform_params_to_database(params)

Takes a dictionary of parameters and recursively translates them into parameters appropriate for sending over Rexpro.

Parameters:params (dict) – The parameters to be sent to the function
Return type:dict
class mogwai.gremlin.base.GremlinValue(path=None, method_name=None, classmethod=False, property=False, defaults=None, transaction=True, imports=None)

Gremlin Method that returns one value

configure_method(klass, attr_name, gremlin_path)

Sets up the methods internals

Parameters:
  • klass (object) – The class object this function is being added to
  • attr_name (str) – The attribute name this function will be added as
  • gremlin_path (str) – The path to the gremlin file containing method
transform_params_to_database(params)

Takes a dictionary of parameters and recursively translates them into parameters appropriate for sending over Rexpro.

Parameters:params (dict) – The parameters to be sent to the function
Return type:dict
mogwai.gremlin.groovy.GroovyFileDef

alias of GroovyFileDefinition

class mogwai.gremlin.groovy.GroovyFunction

GroovyFunction(name, args, body, defn)

args

Alias for field number 1

body

Alias for field number 2

count(value) → integer -- return number of occurrences of value
defn

Alias for field number 3

index(value[, start[, stop]]) → integer -- return first index of value.

Raises ValueError if the value is not present.

name

Alias for field number 0

class mogwai.gremlin.groovy.GroovyFunctionParser

Given a string containing a single function definition this class will parse the function definition and return information regarding it.

FuncDefn = {{{{{"def" Re:('[A-Za-z_]\\w*')} "("} Re:('[A-Za-z_]\\w*') [, Re:('[A-Za-z_]\\w*')]...} ")"} "{"}
FuncName = Re:('[A-Za-z_]\\w*')
KeywordDef = "def"
VarName = Re:('[A-Za-z_]\\w*')
classmethod parse(data)

Parse the given function definition and return information regarding the contained definition.

Parameters:data (str | basestring) – The function definition in a string
Return type:dict
class mogwai.gremlin.groovy.GroovyImport

GroovyImport(comment_list, import_strings, import_list)

comment_list

Alias for field number 0

count(value) → integer -- return number of occurrences of value
import_list

Alias for field number 2

import_strings

Alias for field number 1

index(value[, start[, stop]]) → integer -- return first index of value.

Raises ValueError if the value is not present.

class mogwai.gremlin.groovy.GroovyImportParser

Given a string containing a single import definition this class will parse the import definition and return information regarding it.

CommentVar = comment
ImportDef = Suppress:("import")
ImportDefn = {{{Suppress:("import") Re:('[A-Za-z_.\\*]*') [. Re:('[A-Za-z_.\\*]*')]...} Suppress:(";")} [{Suppress:("//") comment [Empty comment]...}]}
ImportVarName = Re:('[A-Za-z_.\\*]*')
OptionalSpace = [" "]
classmethod parse(data)

Parse the given import and return information regarding the contained import statement.

Parameters:data (str | basestring) – The import statement in a string
Return type:dict
mogwai.gremlin.groovy.parse(filename)

Parse Groovy code in the given file and return a list of information about each function necessary for usage in queries to database.

Parameters:filename (str) – The file containing groovy code.
Return type:list
class mogwai.gremlin.table.Table(gremlin_result)

Table

A table accepts the results of a GremlinTable in it’s constructor. It can be iterated over like a normal list, but within the rows the dictionaries are accessible via .notation

For example:

# returns a table of people & my friend edge to them # the edge contains my nickname for that person friends = mogwai.gremlin.GremlinTable()

def get_friends_and_my_nickname(self):

result = self.friends() for i in result:

print “{}:{}”.format(i.friend_edge.nickname, i.person.name)
next()
class mogwai.gremlin.table.Row(data)

Row

A row represent a table row, from which it’s columns can be accessed like a tuple or dict. Rows are read-only and accept elements or dicts with as initializers as a result of a GremlinTable query. Also the . getattr notation can be used to access elements

Example: row = Row({‘person’: Friend.create(....), ‘myval’: 3}) print “{}:{} - {}”.format(row.friend_edge.nickname, row.person.name, row.myval)

items()
iteritems()
keys()
next()
values()