hydra.overlay.python.tinkerpop.coder module

Bidirectional bridge between Hydra property graphs and TinkerPop (Gremlin) graphs, in Python.

This is the Python counterpart of hydra.overlay.java.tinkerpop.coder (the HydraGremlinBridge + Validate classes). It converts between a live TinkerPop graph (read/written via a gremlinpython GraphTraversalSource) and Hydra’s hydra.pg.model.Graph, and validates a TinkerPop graph against a Hydra GraphSchema using the hydra.validate.pg engine.

Host-specific code: it depends on gremlinpython, so it lives under the hydra.overlay.python.* namespace (only translingual/generated code lives outside hydra.overlay). This module is currently shipped as a binding; it is authored at its eventual overlay namespace so the future migration to overlay/ is a file move, not a rewrite.

class hydra.overlay.python.tinkerpop.coder.Result(error)

Bases: object

The result of validating a graph against a schema. error carries the typed InvalidGraphError (or None when valid).

property error
property is_valid
hydra.overlay.python.tinkerpop.coder.check_literal(lt, lv)

The check_value callback for hydra.validate.pg.validate_graph.

Returns None_() if the literal value matches the expected type, Given(InvalidValueError(...)) otherwise.

hydra.overlay.python.tinkerpop.coder.gremlin_to_hydra(g, value_mapper=<function object_to_literal>)

Read a TinkerPop graph via traversals and convert to a Hydra Graph.

g is a gremlinpython GraphTraversalSource (remote or embedded). Returns a hydra.pg.model.Graph with Literal values.

hydra.overlay.python.tinkerpop.coder.hydra_to_gremlin(graph, g, value_unmapper=<function literal_to_object>)

Write a Hydra Graph into a live TinkerPop graph via traversals.

Upserts by id: existing vertices/edges keep their identity and have properties overwritten; new ones are added. Vertices are written before edges to avoid dangling references within a single call. g may be remote or embedded but must allow writes.

hydra.overlay.python.tinkerpop.coder.literal_family(lit)
hydra.overlay.python.tinkerpop.coder.literal_to_object(literal)

Convert a Hydra Literal to a plain Python value. Inverse of object_to_literal.

hydra.overlay.python.tinkerpop.coder.object_to_literal(obj)

Convert a Python value from gremlinpython to a Hydra Literal.

Handles the types that TinkerPop’s Modern graph uses: str, int, and float (Python float is 64-bit).

hydra.overlay.python.tinkerpop.coder.show_literal(lit)
hydra.overlay.python.tinkerpop.coder.show_literal_type(lt)
hydra.overlay.python.tinkerpop.coder.validate(schema, g)

Validate a TinkerPop graph (via a gremlinpython traversal source) against a schema.

Returns a Result whose repr() is “VALID” or “INVALID - …” and whose error, when present, is a typed InvalidGraphError.