Skip to content

Relation Class API Reference

A relation between two nodes in the database. Has a base type, source and target node IDs, and properties from base type.

Relation class is designed to be instanced by an engine:

friendship = engine.create_relation("alice", "bob", "FRIEND")

Note

Relations are designed to be always unique! Even when you load a database from save of another one. It means you have same relation between same nodes, with same type, and even same values. In short, Graphite is a multigraph. They are hashable based on Python's id() function.

Subject To Change

Other type of graphs, is planned to be available.

Attributes:

  • type_name (str) –

    Name of base RelationType.

  • from_node (str) –

    Source node's ID.

  • to_node (str) –

    Target node's ID.

  • values (dict[str, Any]) –

    A dictionary holding field values. Use set() and get() methods to use it.

    Tip

    Values can be accessed with node["field_name"] too.

  • type_ref (RelationType | None) –

    Reference to RelationType.

Methods:

  • get

    Returns value of a field in this relation.

  • set

    Sets a field in this relation.

Functions

get

get(field_name: str) -> Any

Returns value of a field in this relation.

Parameters:

  • field_name (str) –

    Field name.

Returns:

  • Any

    Value.

set

set(field_name: str, value: Any) -> None

Sets a field in this relation.

Parameters:

  • field_name (str) –

    Field name.

  • value (Any) –

    Value to set.

Subject To Change

Currently type of values can be invalid. This may be fixed in next versions.