1 reference
linarphy edited this page 2026-04-27 04:23:38 +02:00
This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

Reference

Graph

class galaxy_graph.Graph(is_directed: bool = True, nodes: set[Node] = , data: Any = None)

Set of nodes.

add(node: Node) → Node

Add an offline Node to this Graph.

connect(source: Node, connection: Connection, destination: Node) → Graph

Add two node with a connection quickly.

The two created node and connection will be added to the graph. If the graph of the node is not directed, each node will have the same connection.

  • Parameters:
    • source (Node) First node of the connection. If graph is directed, origin of the arrow
    • connection (Connection) Connection linking the first and the second node. This connection must not have been already used in another link.
    • destination (Node) Last node of the connection. If graph is directed, pointing of the arrow.

data : Any = None

delete(node_id: str) → Node

Delete a node and all of its connections.

get_by_class(class_: type[Node]) → set[Node]

Get all node of a given class.

get_by_data(filter_: Callable[[__annotationlib_name_1__], __annotationlib_name_2__]) → set[Node]

Get all node of the graph respecting a condition on its data.

Return every nodes for which applying the nodes data to filter return True.

get_by_id(node_id: str) → Node

Get a node from its node identifier.

internal_add_node(node: Node) → None

Add a node to the graph.

Internal use only.

internal_delete_node(node: Node) → None

Delete a node and all of its connections to other nodes.

Internal use only.

is_directed : bool = True

Node

Sub-module that contains behavior and state about Node.

class galaxy_graph.node.Node(identifier: str = , data: Any = None)

Bases: object

Singular element storing data.

Can be connected to other node and be a part of a Graph.

connect(connection: Connection, destination: Node) → Connection

Connect this node to another one with a specific connection.

If the graph of the node is not directed, the other node will have the same connection.

Notes

This should be used on Node that are online !

  • Parameters:
    • connection (Connection) Connection not already connected to nodes.
    • destination (Node) Node already in the Graph or not.
  • Raises: NodeOfflineError If the Node is not in a graph.

data : Any = None

identifier : str

state : NodeState

class galaxy_graph.node.NodeIsOffline(state: NodeState)

Bases: NodeOnlineState

The Node is not in a Graph.

attach(graph: Graph) → Node

Attach the Node to a Graph.

is_online() → bool

Check if the Node is associated to a Graph.

class galaxy_graph.node.NodeIsOnline(state: NodeState, graph: Graph, connections: set[Connection] = )

Bases: NodeOnlineState

The Node is in a Graph.

connect(connection: Connection, destination: Node) → Connection

Connect this node to another one with a specific connection.

If the graph of the node is not directed, the other node will have the same connection.

  • Parameters:
    • connection (Connection) Connection not already connected to nodes.
    • destination (Node) Node already in a Graph or not.

detach() → Node

Detach the node to its attached Graph.

get_neighbors_by_connection_data(filter_: Callable[[__annotationlib_name_1__], __annotationlib_name_2__]) → set[Node]

Get linked nodes with connections respecting a filter on data.

The filter function will be applied to the data of every connections of this node. If the filter return true, the node associated to the connection is included in the returned set.

  • Parameters: filter (Callable [ *[*Any ] , bool ]) Filter function, determine if the connected Node is kept.

Examples

>>> node = Node()
>>> node_1 = Node()
>>> node_2 = Node()
>>> node.connect(Connection, node_1, 2)
>>> node.connect(Connection, node_2, 14)
>>> node.get_neighbors_by_connection_data(
>>>     filter=lambda x: x < 10
>>>     if isinstance(x, int) else False,
>>> )
{ node_1 }

get_neighbors_by_connection_type(type_: type[Connection]) → set[Node]

Get linked nodes with connections of the given types.

  • Parameters: type (type [Connection ]) Type of the connection to look at.

get_neighbors_by_node_data(filter_: Callable[[__annotationlib_name_1__], __annotationlib_name_2__]) → set[Node]

Get linked nodes with data respecting a given filter.

The filter function will be applied to the data of every nodes connected to this node. If the filter return true, the node is included in the returned set.

  • Parameters: filter (Callable [ *[*Any ] , bool ]) Filter function, determine if the connected Node is kept.

Examples

>>> node = Node()
>>> node_1 = Node(data=5)
>>> node_2 = Node(data=12)
>>> node.connect(Connection, node_1)
>>> node.connect(Connection, node_2)
>>> node.get_neighbors_by_node_data(
>>>     filter=lambda x: x < 9 if isinstance(x, int) else False,
>>> )
{ node_1 }

get_neighbors_by_node_type(type_: type[Node]) → set[Node]

Get linked node with a given type.

  • Parameters: type (type [Node ]) Type of the node to look at.

is_online() → bool

Check if the Node is associated to a Graph.

class galaxy_graph.node.NodeOnlineState(state: NodeState)

Bases: object

Information if the Node is in a Graph.

is_online() → bool

Check if the Node is associated to a Graph.

class galaxy_graph.node.NodeState(node: Node)

Bases: object

States of the node that modify the Node behavior.

is_online() → bool

Check if the Node is associated to a Graph.

Connection

Sub-module that contains behavior and state about Connection.

class galaxy_graph.connection.Connection(data: Any = None, identifier: str = )

Bases: object

Connection between two nodes from the same graph.

data : Any = None

identifier : str

state : ConnectionState

class galaxy_graph.connection.ConnectionNotSetup(state: ConnectionState)

Bases: ConnectionSetupState

The Connection is not setup yet.

is_setup() → bool

Check if the Connection is associated to Nodes.

setup(source: Node, destination: Node) → Connection

Associate this Connection to two Nodes.

  • Parameters:
    • source (Node) First node of the connection (its source).
    • destination (Node) Last node of the connection (pointing of the arrow).

class galaxy_graph.connection.ConnectionSetup(state: ConnectionState, source: Node, destination: Node)

Bases: ConnectionSetupState

The Connection is setup.

is_setup() → bool

Check if the Connection is associated to Nodes.

class galaxy_graph.connection.ConnectionSetupState(state: ConnectionState)

Bases: object

Information if the Connection is already setup.

If the connection is setup, it has a source and a destination and cannot be updated anymore.

is_setup() → bool

Check if the Connection is associated to Nodes.

class galaxy_graph.connection.ConnectionState(connection: Connection)

Bases: object

States of the connection that modify the Connection behavior.

is_setup() → bool

Check if the Connection is associated to Nodes.

Exception

Exception of this module.

exception galaxy_graph.exception.ConnectionAlreadyInNodeError(identifier: str)

Bases: Exception

The connection is already in the node.

exception galaxy_graph.exception.ConnectionAlreadySetupError(identifier: str)

Bases: Exception

The connection is already setup.

exception galaxy_graph.exception.NodeAlreadyInGraphError(identifier: str)

Bases: Exception

Node already in graph.

exception galaxy_graph.exception.NodeNotFoundError(identifier: str)

Bases: Exception

Node not found.

exception galaxy_graph.exception.NodeOfflineError(identifier: str)

Bases: Exception

Node is not online.