goblin package

Submodules

goblin.abc module

class goblin.abc.BaseProperty[source]

Bases: object

Abstract base class that implements the property interface

data_type
class goblin.abc.DataType(val=None)[source]

Bases: abc.ABC

Abstract base class for Goblin Data Types. All custom data types should inherit from DataType.

to_db(val=None)[source]

Convert property value to db compatible format. If no value passed, try to use default bound value

to_ogm(val)[source]

Convert property value to a Python compatible format

validate(val)[source]

Validate property value

validate_vertex_prop(val, card, vertex_prop, data_type)[source]

goblin.app module

Goblin application class and class constructor

class goblin.app.Goblin(cluster, *, provider=<class 'goblin.provider.TinkerGraph'>, get_hashable_id=None, aliases=None)[source]

Bases: object

Class used to encapsulate database connection configuration and generate database connections Used as a factory to create Session objects.

Parameters:
  • url (str) – Database url
  • loop (asyncio.BaseEventLoop) – Event loop implementation
  • features (dict) – Vendor implementation specific database features
  • config (dict) – Config parameters for application
close()[source]
cluster
config
config_from_file(filename)[source]

Load configuration from from file.

Parameters:filename (str) – Path to the configuration file.
config_from_json(filename)[source]

Load configuration from from JSON file.

Parameters:filename (str) – Path to the configuration file.
config_from_module(module)[source]
config_from_yaml(filename)[source]
edges

Registered edge classes

classmethod open(loop, *, provider=<class 'goblin.provider.TinkerGraph'>, get_hashable_id=None, aliases=None, **config)[source]
register(*elements)[source]

Register user created Element classes.

Parameters:elements (goblin.element.Element) – User defined Element classes
register_from_module(module, *, package=None)[source]
session(*, processor='', op='eval', aliases=None)[source]

Create a session object.

Returns:Session object
url

Database url

vertices

Registered vertex classes

goblin.element module

class goblin.element.Edge(source=None, target=None)[source]

Bases: goblin.element.Element

Base class for user defined Edge classes.

Parameters:
  • source (Vertex) – Source (outV) vertex
  • target (Vertex) – Target (inV) vertex
delsource()[source]
deltarget()[source]
classmethod from_dict(d)[source]
getsource()[source]
gettarget()[source]
setsource(vertex)[source]
settarget(vertex)[source]
source
target
to_dict(source=None, target=None)[source]
class goblin.element.Element(**kwargs)[source]

Bases: object

Base class for classes that implement the Element property interface

id
class goblin.element.ElementMeta[source]

Bases: type

Metaclass for graph elements. Responsible for creating the Mapping object and replacing user defined property.Property with property.PropertyDescriptor.

class goblin.element.GenericEdge(source=None, target=None)[source]

Bases: goblin.element.Edge

Class used to build edges when user defined edges class is not available. Generally not instantiated by end user.

class goblin.element.GenericVertex(**kwargs)[source]

Bases: goblin.element.Vertex

Class used to build vertices when user defined vertex class is not available. Generally not instantiated by end user.

class goblin.element.Vertex(**kwargs)[source]

Bases: goblin.element.Element

Base class for user defined Vertex classes

classmethod from_dict(d)[source]
to_dict()[source]
class goblin.element.VertexProperty(data_type, *, default=None, db_name=None, card=None, db_name_factory=None)[source]

Bases: goblin.element.Element, goblin.abc.BaseProperty

Base class for user defined vertex properties.

cardinality
data_type
db_name
db_name_factory
default
from_dict(d)[source]
getdb_name()[source]
getvalue()[source]
setgetdb_name(val)[source]
setvalue(val)[source]
to_dict()[source]
value
class goblin.element.VertexPropertyDescriptor(name, vertex_property)[source]

Bases: object

Descriptor that validates user property input and gets/sets properties as instance attributes.

goblin.exception module

exception goblin.exception.ClientError[source]

Bases: Exception

exception goblin.exception.ConfigError[source]

Bases: Exception

exception goblin.exception.ConfigurationError[source]

Bases: Exception

exception goblin.exception.ElementError[source]

Bases: Exception

exception goblin.exception.GremlinServerError[source]

Bases: Exception

exception goblin.exception.MappingError[source]

Bases: Exception

exception goblin.exception.ResponseTimeoutError[source]

Bases: Exception

exception goblin.exception.ValidationError[source]

Bases: Exception

goblin.manager module

Managers for multi cardinality vertex properties

class goblin.manager.ListVertexPropertyManager(data_type, vertex_prop, card, obj)[source]

Bases: list, goblin.manager.VertexPropertyManager

append(val)[source]
vp_map
class goblin.manager.SetVertexPropertyManager(data_type, vertex_prop, card, obj)[source]

Bases: set, goblin.manager.VertexPropertyManager

add(val)[source]
class goblin.manager.VertexPropertyManager(data_type, vertex_prop, card)[source]

Bases: object

mapper_func

goblin.mapper module

Helper functions and class to map between OGM Elements <-> DB Elements

class goblin.mapper.Mapping(namespace, element_type, mapper_func, properties)[source]

Bases: object

This class stores the information necessary to map between an OGM element and a DB element.

db_properties

A dictionary of property mappings

label

Element label

mapper_func

Function responsible for mapping db results to ogm

ogm_properties

A dictionary of property mappings

goblin.mapper.create_mapping(namespace, properties)[source]

Constructor for Mapping

goblin.mapper.get_hashable_id(val)[source]
goblin.mapper.get_metaprops(vertex_property, mapping)[source]
goblin.mapper.map_edge_to_ogm(result, props, element, *, mapping=None)[source]

Map an edge returned by DB to OGM edge

goblin.mapper.map_props_to_db(element, mapping)[source]

Convert OGM property names/values to DB property names/values

goblin.mapper.map_vertex_property_to_ogm(result, element, *, mapping=None)[source]

Map a vertex returned by DB to OGM vertex

goblin.mapper.map_vertex_to_ogm(result, props, element, *, mapping=None)[source]

Map a vertex returned by DB to OGM vertex

goblin.properties module

Classes to handle properties and data type definitions

class goblin.properties.Boolean(val=None)[source]

Bases: goblin.abc.DataType

Simple boolean datatype

to_db(val=None)[source]
to_ogm(val)[source]
validate(val)[source]
class goblin.properties.Float(val=None)[source]

Bases: goblin.abc.DataType

Simple float datatype

to_db(val=None)[source]
to_ogm(val)[source]
validate(val)[source]
class goblin.properties.Generic(val=None)[source]

Bases: goblin.abc.DataType

to_db(val=None)[source]
to_ogm(val)[source]
validate(val)[source]
class goblin.properties.IdProperty(data_type, *, serializer=None)[source]

Bases: goblin.abc.BaseProperty

data_type
serializer
class goblin.properties.IdPropertyDescriptor(name, prop)[source]

Bases: object

class goblin.properties.Integer(val=None)[source]

Bases: goblin.abc.DataType

Simple integer datatype

to_db(val=None)[source]
to_ogm(val)[source]
validate(val)[source]
class goblin.properties.Property(data_type, *, db_name=None, default=None, db_name_factory=None)[source]

Bases: goblin.abc.BaseProperty

API class used to define properties. Replaced with PropertyDescriptor by goblin.element.ElementMeta.

Parameters:
  • data_type (goblin.abc.DataType) – Str or class of data type
  • db_name (str) – User defined custom name for property in db
  • default – Default value for this property.
data_type
db_name
db_name_factory
default
getdb_name()[source]
setgetdb_name(val)[source]
class goblin.properties.PropertyDescriptor(name, prop)[source]

Bases: object

Descriptor that validates user property input and gets/sets properties as instance attributes. Not instantiated by user.

class goblin.properties.String(val=None)[source]

Bases: goblin.abc.DataType

Simple string datatype

to_db(val=None)[source]
to_ogm(val)[source]
validate(val)[source]
goblin.properties.default_id_serializer(val)[source]
goblin.properties.noop_factory(x, y)[source]

goblin.session module

Main OGM API classes and constructors

class goblin.session.Session(app, remote_connection, get_hashable_id)[source]

Bases: object

Provides the main API for interacting with the database. Does not necessarily correpsond to a database session. Don’t instantiate directly, instead use Goblin.session.

Parameters:
add(*elements)[source]

Add elements to session pending queue.

Parameters:elements (goblin.element.Element) – Elements to be added
app
close()[source]
current
flush()[source]

Issue creation/update queries to database for all elements in the session pending queue.

g

Get a simple traversal source.

Returns:goblin.gremlin_python.process.GraphTraversalSource object
get_edge(edge)[source]

Get a edge from the db. Edge must have id.

Parameters:element (goblin.element.Edge) – Edge to be retrieved
Returns:Edge | None
get_vertex(vertex)[source]

Get a vertex from the db. Vertex must have id.

Parameters:element (goblin.element.Vertex) – Vertex to be retrieved
Returns:Vertex | None
graph
remote_connection
remove_edge(edge)[source]

Remove an edge from the db.

Parameters:edge (goblin.element.Edge) – Element to be removed
remove_vertex(vertex)[source]

Remove a vertex from the db.

Parameters:vertex (goblin.element.Vertex) – Vertex to be removed
save(elem)[source]

Save an element to the db.

Parameters:element (goblin.element.Element) – Vertex or Edge to be saved
Returns:Element object
save_edge(edge)[source]

Save an edge to the db.

Parameters:element (goblin.element.Edge) – Edge to be saved
Returns:Edge object
save_vertex(vertex)[source]

Save a vertex to the db.

Parameters:element (goblin.element.Vertex) – Vertex to be saved
Returns:Vertex object
submit(bytecode)[source]

Submit a query to the Gremiln Server.

Parameters:
  • gremlin (str) – Gremlin script to submit to server.
  • bindings (dict) – A mapping of bindings for Gremlin script.
Returns:

TraversalResponse object

traversal(element_class=None)[source]

Generate a traversal using a user defined element class as a starting point.

Parameters:element_class (goblin.element.Element) – An optional element class that will dictate the element type (vertex/edge) as well as the label for the traversal source
Returns:AsyncGraphTraversal
goblin.session.bindprop(element_class, ogm_name, val, *, binding=None)[source]

Helper function for binding ogm properties/values to corresponding db properties/values for traversals.

Parameters:
  • element_class (goblin.element.Element) – User defined element class
  • ogm_name (str) – Name of property as defined in the ogm
  • val – The property value
  • binding (str) – The binding for val (optional)
Returns:

tuple object (‘db_property_name’, (‘binding(if passed)’, val))

Module contents