graphi.edge module

class graphi.edge.Edge(start, stop, step=None)

Bases: object

An edge in a graph as a pair of nodes

  • start – the start or tail of an edge
  • stop – the stop or head of an edge
  • step – currently unused

This is a verbose interface for creating edges between nodes for use in a graph. It allows using slice notation independent of a graph:

>>> atb = Edge[a:b]
>>> a2b = Edge(a, b)
>>> graph[a2b] = 1337
>>> graph[a:b] == graph[atb] == graph[a2b] == graph[Edge[a:b]] == graph[Edge(a, b)]

A Edge can also be used for explicit containment tests:

>>> Edge[a:b] in graph

In addition to their slice-like nature, Edge is iterable and indexable. This allows for easy unpacking:

>>> edge = Edge[a:b]
>>> tail, head = edge


This class creates a representation of an edge as a connection between nodes. Edge values can be arbitrary objects.


Even though Edge behaves like a slice in graphs, builtin containers such as list cannot make use of an Edge.

class graphi.edge.EdgeMeta

Bases: type

Metaclass for Edge to support Edge[a:b]

class graphi.edge.Loop(start, stop=None, step=None)

Bases: graphi.edge.Edge

An edge in a graph from a node to itself

  • start – the start or tail of a loop
  • stop – optional stop or head of a loop, same as start
  • step – currently unused

ValueError – if stop is given but not equal to start