goblin.models package

Submodules

goblin.models.edge module

class goblin.models.edge.Edge(outV, inV, **values)[source]

Bases: goblin.models.element.Element

Base class for all edges.

FACTORY_CLASS = None
classmethod all(ids, as_dict=False, *args, **kwargs)[source]

Load all edges with the given edge_ids from the graph. By default this will return a list of edges but if as_dict is True then it will return a dictionary containing edge_ids as keys and edges found as values.

Parameters:
  • ids (list) – A list of titan IDs
  • as_dict (boolean) – Toggle whether to return a dictionary or list
Return type:

dict | list

classmethod create(outV, inV, label=None, *args, **kwargs)[source]

Create a new edge of the current type coming out of vertex outV and going into vertex inV with the given properties.

Parameters:
  • outV (Vertex) – The vertex the edge is coming out of
  • inV (Vertex) – The vertex the edge is going into
delete(**kwargs)[source]

Delete the current edge from the graph.

classmethod find_by_value(field, value, as_dict=False, **kwargs)[source]

Returns edges that match the given field/value pair.

Parameters:
  • field (str) – The field to search
  • value (str) – The value of the field
  • as_dict (boolean) – Return results as a dictionary
Return type:

[goblin.models.Edge]

classmethod get(id, *args, **kwargs)[source]

Look up edge by titan assigned ID. Raises a DoesNotExist exception if an edge with the given edge id was not found. Raises a MultipleObjectsReturned exception if the edge_id corresponds to more than one edge in the graph.

Parameters:id (str | basestring) – The titan assigned ID
Return type:goblin.models.Edge
classmethod get_between(outV, inV, page_num=None, per_page=None)[source]

Return all the edges with a given label between two vertices.

Parameters:
  • outV (Vertex) – The vertex the edge comes out of.
  • inV (Vertex) – The vertex the edge goes into.
  • page_num (int) – The page number of the results
  • per_page (int) – The number of results per page
Return type:

list

classmethod get_label()[source]

Returns the label for this edge.

Return type:str
gremlin_path = 'edge.groovy'
inV(*args, **kwargs)[source]

Return the vertex that this edge goes into.

Return type:Vertex
label = None
outV(*args, **kwargs)[source]

Return the vertex that this edge goes into.

Return type:Vertex
save(*args, **kwargs)[source]

Save this edge to the graph database.

validate()[source]

Perform validation of this edge raising a ValidationError if any problems are encountered.

class goblin.models.edge.EdgeMetaClass[source]

Bases: goblin.models.element.ElementMetaClass

Metaclass for edges.

goblin.models.element module

class goblin.models.element.BaseElement(**values)[source]

Bases: object

The base model class, don’t inherit from this, inherit from Model, defined below

exception DoesNotExist[source]

Bases: goblin.exceptions.GoblinException

Object not found in database

BaseElement.FACTORY_CLASS = None
exception BaseElement.MultipleObjectsReturned[source]

Bases: goblin.exceptions.GoblinException

Multiple objects returned on unique key lookup

exception BaseElement.WrongElementType[source]

Bases: goblin.exceptions.GoblinException

Unique lookup with key corresponding to vertex of different type

BaseElement.as_dict()[source]

Returns a map of column names to cleaned values

Return type:dict
BaseElement.as_save_params()[source]

Returns a map of property names to cleaned values containing only the properties which should be persisted on save.

Return type:dict
classmethod BaseElement.create(*args, **kwargs)[source]

Create a new element with the given information.

classmethod BaseElement.get_property_by_name(key)[source]

Get’s the db_field_name of a property by key

Parameters:key (basestring | str) – attribute of the model
Return type:basestring | str | None
BaseElement.id
BaseElement.items()[source]
BaseElement.keys()[source]
BaseElement.label
BaseElement.pre_save()[source]

Pre-save hook which is run before saving an element

BaseElement.pre_update(**values)[source]

Override this to perform pre-update validation

BaseElement.reload(*args, **kwargs)[source]

Reload the given element from the database.

BaseElement.save()[source]

Base class save method. Performs basic validation and error handling.

classmethod BaseElement.translate_db_fields(data)[source]

Translates field names from the database into field names used in our model this is for cases where we’re saving a field under a different name than it’s model property

Parameters:data – dict
Return type:dict
BaseElement.update(**values)[source]

performs an update of this element with the given values and returns the saved object

BaseElement.validate()[source]

Cleans and validates the field values

BaseElement.validate_field(field_name, val)[source]

Perform the validations associated with the field with the given name on the value passed.

Parameters:
  • field_name (str) – The name of property whose validations will be run
  • val (mixed) – The value to be validated
BaseElement.values()[source]
class goblin.models.element.Element(**values)[source]

Bases: goblin.models.element.BaseElement

classmethod deserialize(data)[source]

Deserializes rexpro response into vertex or edge objects

gremlin_path = None
class goblin.models.element.ElementMetaClass[source]

Bases: type

Metaclass for all graph elements

goblin.models.query module

class goblin.models.query.V(vertex)[source]

Bases: object

All query operations return a new query object, which currently deviates from blueprints. The blueprints query object modifies and returns the same object This method seems more flexible, and consistent w/ the rest of Gremlin.

both(*labels)[source]
both_e(*labels)[source]
both_v()[source]
count(*args, **kwargs)[source]
Returns:number of matching vertices
Return type:int
get(deserialize=True, *args, **kwargs)[source]
has(key, value, compare='eq')[source]
Parameters:
  • key (str | goblin.properties.GraphProperty) – key to lookup
  • value (str, float, int) – value to compare
  • compare (str) – comparison keyword
Return type:

Query

has_id(*ids)[source]
has_label(*labels)[source]
in_e(*labels)[source]
in_step(*labels)[source]
in_v()[source]
limit(limit)[source]
other_v()[source]
out_e(*labels)[source]
out_step(*labels)[source]
out_v()[source]

goblin.models.vertex module

class goblin.models.vertex.EnumVertexBaseMeta[source]

Bases: goblin.models.vertex.VertexMetaClass

This metaclass allows you to access MyVertexModel as if it were an enum. Ex. MyVertexModel.FOO

The values are cached in a dictionary. This is useful if the number of MyVertexModels is small, however it it grows too large, you should be doing it a different way.

This looks for a special (optional) function named enum_generator in your model and calls that to generate the ENUM for the model.

There is an additional optional model attribute that can be set __enum_id_only__ (defaults to True) which dictates whether or not just the Vertex ID is stored, or the whole Vertex in cache.

enums = None
class goblin.models.vertex.Vertex(**values)[source]

Bases: goblin.models.element.Element

The Vertex model base class.

The element type is auto-generated from the subclass name, but can optionally be set manually

FACTORY_CLASS = None
classmethod all(ids=[], as_dict=False, match_length=True, *args, **kwargs)[source]

Load all vertices with the given ids from the graph. By default this will return a list of vertices but if as_dict is True then it will return a dictionary containing ids as keys and vertices found as values.

Parameters:
  • ids (list) – A list of titan ids
  • as_dict (boolean) – Toggle whether to return a dictionary or list
Return type:

dict | list

bothE(*labels, **kwargs)[source]

Return a list of edges both incoming and outgoing from this vertex.

Parameters:
  • label (str or BaseEdge or None) – The edge label to be traversed (optional)
  • limit (int or None) – The number of the page to start returning results at
  • offset (int or None) – The maximum number of results to return
  • types (list) – A list of allowed element types
bothV(*labels, **kwargs)[source]

Return a list of vertices both incoming and outgoing from this vertex.

Parameters:
  • label (str or BaseEdge or None) – The edge label to be traversed (optional)
  • limit (int or None) – The number of the page to start returning results at
  • offset (int or None) – The maximum number of results to return
  • types (list) – A list of allowed element types
delete(**kwargs)[source]

Delete the current vertex from the graph.

delete_inE(*labels, **kwargs)[source]

Delete all incoming edges with the given label.

delete_inV(*labels, **kwargs)[source]

Delete all incoming vertices connected with edges with the given label.

delete_outE(*labels, **kwargs)[source]

Delete all outgoing edges with the given label.

delete_outV(*labels, **kwargs)[source]

Delete all outgoing vertices connected with edges with the given label.

classmethod find_by_value(field, value, as_dict=False)[source]

Returns vertices that match the given field/value pair.

Parameters:
  • field (str) – The field to search
  • value (str) – The value of the field
  • as_dict (boolean) – Return results as a dictionary
Return type:

[goblin.models.Vertex]

classmethod get(id, *args, **kwargs)[source]

Look up vertex by its ID. Raises a DoesNotExist exception if a vertex with the given vid was not found. Raises a MultipleObjectsReturned exception if the vid corresponds to more than one vertex in the graph.

Parameters:id (str) – The ID of the vertex
Return type:goblin.models.Vertex
classmethod get_label()[source]

Returns the element type for this vertex.

@returns: str

gremlin_path = 'vertex.groovy'
inE(*labels, **kwargs)[source]

Return a list of edges with the given label coming into this vertex.

Parameters:
  • label (str or BaseEdge) – The edge label to be traversed
  • limit (int or None) – The number of the page to start returning results at
  • offset (int or None) – The maximum number of results to return
  • types (list) – A list of allowed element types
inV(*labels, **kwargs)[source]

Return a list of vertices reached by traversing the incoming edge with the given label.

Parameters:
  • label (str or BaseEdge) – The edge label to be traversed
  • limit (int or None) – The number of the page to start returning results at
  • offset (int or None) – The maximum number of results to return
  • types (list) – A list of allowed element types
label = None
outE(*labels, **kwargs)[source]

Return a list of edges with the given label going out of this vertex.

Parameters:
  • label (str or BaseEdge) – The edge label to be traversed
  • limit (int or None) – The number of the page to start returning results at
  • offset (int or None) – The maximum number of results to return
  • types (list) – A list of allowed element types
outV(*labels, **kwargs)[source]

Return a list of vertices reached by traversing the outgoing edge with the given label.

Parameters:
  • labels (str or BaseEdge) – pass in the labels to follow in as positional arguments
  • limit (int or None) – The number of the page to start returning results at
  • offset (int or None) – The maximum number of results to return
  • types (list) – A list of allowed element types
query()[source]
save(*args, **kwargs)[source]

Save the current vertex using the configured save strategy, the default save strategy is to re-save all fields every time the object is saved.

class goblin.models.vertex.VertexMetaClass[source]

Bases: goblin.models.element.ElementMetaClass

Metaclass for vertices.