edgygraph 0.0.7__tar.gz

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.
@@ -0,0 +1,6 @@
1
+ Metadata-Version: 2.4
2
+ Name: edgygraph
3
+ Version: 0.0.7
4
+ Summary: Graph-based Pipeline Builder
5
+ Author: Mathis Siebert
6
+ Requires-Python: >=3.11
@@ -0,0 +1 @@
1
+ # Graph-based Pipeline Builder
@@ -0,0 +1,13 @@
1
+ from .edges import GraphEdge, START, END
2
+ from .nodes import GraphNode
3
+ from .states import GraphState
4
+ from .graph import GraphExecutor
5
+
6
+ __all__ = [
7
+ "GraphEdge",
8
+ "GraphNode",
9
+ "GraphState",
10
+ "GraphExecutor",
11
+ "START",
12
+ "END",
13
+ ]
@@ -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
@@ -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 = 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: GraphState = await next_node.run(state)
33
+ current_node = next_node
34
+
35
+ return state
@@ -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
File without changes
@@ -0,0 +1,28 @@
1
+ from pydantic import BaseModel, Field
2
+ from typing import TypeVar, AsyncIterator, Protocol, Generic
3
+ from types import TracebackType
4
+
5
+ class GraphState(BaseModel):
6
+ vars: dict[str, object] = Field(default_factory=dict)
7
+
8
+
9
+ T = TypeVar('T', covariant=True)
10
+
11
+ class Stream(AsyncIterator[T], Protocol):
12
+ async def aclose(self) -> None: ...
13
+
14
+ async def __aenter__(self) -> "Stream[T]":
15
+ return self
16
+
17
+ async def __aexit__(
18
+ self, exc_type: type[BaseException] | None,
19
+ exc: BaseException | None,
20
+ tb: TracebackType | None
21
+ ) -> None: # Not handling exceptions here -> returns None
22
+
23
+ await self.aclose()
24
+
25
+
26
+ class GraphStateStream(GraphState, Generic[T]):
27
+
28
+ stream: Stream[T] | None = None
@@ -0,0 +1,6 @@
1
+ Metadata-Version: 2.4
2
+ Name: edgygraph
3
+ Version: 0.0.7
4
+ Summary: Graph-based Pipeline Builder
5
+ Author: Mathis Siebert
6
+ Requires-Python: >=3.11
@@ -0,0 +1,12 @@
1
+ README.md
2
+ pyproject.toml
3
+ edgygraph/__init__.py
4
+ edgygraph/edges.py
5
+ edgygraph/graph.py
6
+ edgygraph/nodes.py
7
+ edgygraph/py.typed
8
+ edgygraph/states.py
9
+ edgygraph.egg-info/PKG-INFO
10
+ edgygraph.egg-info/SOURCES.txt
11
+ edgygraph.egg-info/dependency_links.txt
12
+ edgygraph.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ edgygraph
@@ -0,0 +1,12 @@
1
+ [project]
2
+ name = "edgygraph"
3
+ version = "0.0.7"
4
+ description = "Graph-based Pipeline Builder"
5
+ authors = [{ name="Mathis Siebert" }]
6
+ requires-python = ">=3.11"
7
+ dependencies = []
8
+
9
+ [build-system]
10
+ requires = ["setuptools", "wheel"]
11
+ build-backend = "setuptools.build_meta"
12
+
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+