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:
-
classmethod
find_by_value
(field, value, as_dict=False, **kwargs)[source]¶ Returns edges that match the given field/value pair.
Parameters: 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: Return type:
-
gremlin_path
= 'edge.groovy'¶
-
label
= None¶
-
-
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_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.
label
¶
-
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
-
exception
-
class
goblin.models.element.
Element
(**values)[source]¶ Bases:
goblin.models.element.BaseElement
-
gremlin_path
= None¶
-
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.
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_inV
(*labels, **kwargs)[source]¶ Delete all incoming vertices connected with 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: 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
-
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
-
-
class
goblin.models.vertex.
VertexMetaClass
[source]¶ Bases:
goblin.models.element.ElementMetaClass
Metaclass for vertices.