edgygraph 0.0.11__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
edgygraph/__init__.py ADDED
@@ -0,0 +1,14 @@
1
+ from .edges import GraphEdge, START, END
2
+ from .nodes import GraphNode
3
+ from .states import GraphState, Stream
4
+ from .graph import GraphExecutor
5
+
6
+ __all__ = [
7
+ "GraphEdge",
8
+ "GraphNode",
9
+ "GraphState",
10
+ "Stream",
11
+ "GraphExecutor",
12
+ "START",
13
+ "END",
14
+ ]
edgygraph/edges.py ADDED
@@ -0,0 +1,22 @@
1
+ from typing import Callable, Type, TypeVar, Generic
2
+ from .states import GraphState
3
+ from .nodes import GraphNode
4
+
5
+
6
+ class START:
7
+ pass
8
+
9
+ class END:
10
+ pass
11
+
12
+
13
+ T = TypeVar('T', bound=GraphState)
14
+
15
+ class GraphEdge(Generic[T]):
16
+
17
+ source: GraphNode[T] | Type[START]
18
+ next: Callable[[T], GraphNode[T] | Type[END]]
19
+
20
+ def __init__(self, source: GraphNode[T] | Type[START], next: Callable[[T], GraphNode[T] | Type[END]]):
21
+ self.source = source
22
+ self.next = next
edgygraph/graph.py ADDED
@@ -0,0 +1,35 @@
1
+ from .edges import GraphEdge, START, END
2
+ from .nodes import GraphNode
3
+ from .states import GraphState
4
+ from typing import Type, TypeVar, Generic
5
+
6
+ T = TypeVar('T', bound=GraphState)
7
+
8
+ class GraphExecutor(Generic[T]):
9
+
10
+ edges: list[GraphEdge[T]]
11
+
12
+ def __init__(self, edges: list[GraphEdge[T]]):
13
+ self.edges = edges
14
+
15
+ async def __call__(self, initial_state: T) -> T:
16
+ state: T = initial_state
17
+ current_node: GraphNode[T] | Type[START] = START
18
+
19
+ index_dict: dict[GraphNode[T] | Type[START], GraphEdge[T]] = {edge.source: edge for edge in self.edges}
20
+
21
+ while True:
22
+ # Find the edge corresponding to the current node
23
+ edge: GraphEdge[T] = index_dict[current_node]
24
+ # Determine the next node using the edge's next function
25
+ next_node = edge.next(state)
26
+
27
+ if next_node == END:
28
+ break
29
+ else:
30
+ assert isinstance(next_node, GraphNode)
31
+ # Run the current node to update the state
32
+ state: T = await next_node.run(state)
33
+ current_node = next_node
34
+
35
+ return state
edgygraph/nodes.py ADDED
@@ -0,0 +1,12 @@
1
+ from abc import ABC, abstractmethod
2
+ from .states import GraphState
3
+ from typing import TypeVar, Generic
4
+
5
+
6
+ T = TypeVar('T', bound=GraphState)
7
+
8
+ class GraphNode(ABC, Generic[T]):
9
+
10
+ @abstractmethod
11
+ async def run(self, state: T) -> T:
12
+ pass
edgygraph/py.typed ADDED
File without changes
edgygraph/states.py ADDED
@@ -0,0 +1,27 @@
1
+ from pydantic import BaseModel, Field
2
+ from typing import TypeVar, AsyncIterator, Protocol, Generic
3
+ from types import TracebackType
4
+
5
+
6
+ T = TypeVar('T', covariant=True, default=object)
7
+
8
+ class Stream(AsyncIterator[T], Protocol):
9
+ async def aclose(self) -> None: ...
10
+
11
+ async def __aenter__(self) -> "Stream[T]":
12
+ return self
13
+
14
+ async def __aexit__(
15
+ self, exc_type: type[BaseException] | None,
16
+ exc: BaseException | None,
17
+ tb: TracebackType | None
18
+ ) -> None: # Not handling exceptions here -> returns None
19
+
20
+ await self.aclose()
21
+
22
+
23
+ S = TypeVar('S', bound=Stream, contravariant=True, default=Stream)
24
+
25
+ class GraphState(BaseModel, Generic[T]):
26
+ vars: dict[str, object] = Field(default_factory=dict)
27
+ streams: dict[str, T] = Field(default_factory=dict)
@@ -0,0 +1,6 @@
1
+ Metadata-Version: 2.4
2
+ Name: edgygraph
3
+ Version: 0.0.11
4
+ Summary: Graph-based Pipeline Builder
5
+ Author: Mathis Siebert
6
+ Requires-Python: >=3.13
@@ -0,0 +1,10 @@
1
+ edgygraph/__init__.py,sha256=L4CHY_1tID4NTEO4XyH-8CNLPUWbZ9vh4u2mjaEIe8I,267
2
+ edgygraph/edges.py,sha256=J_zxFfQaGuQuMg3TohuHlfcDlCo5lpoa3tHowe1d-Jk,476
3
+ edgygraph/graph.py,sha256=cvDsyAXGCr4RfWIOcM7XFy9_L6gwa-qbRlan1Z7BPIU,1136
4
+ edgygraph/nodes.py,sha256=tIWg59M1n3D7u7EvloiVt6SioZZj5GW0m6zAayksy3M,252
5
+ edgygraph/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ edgygraph/states.py,sha256=CkYNtmgvmoN1witDFPEHYcc8bTyXVMrxQchS9gCQ10M,812
7
+ edgygraph-0.0.11.dist-info/METADATA,sha256=HesifsK8qWhUpeaHEBcJK6GfKcSLVlNLduUcE38HNv4,139
8
+ edgygraph-0.0.11.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
9
+ edgygraph-0.0.11.dist-info/top_level.txt,sha256=1aTnTyO0rVyypQxuzthXouPY8XY6ybCuRrRvS4FNLeY,10
10
+ edgygraph-0.0.11.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ edgygraph