Skip to main content

High-performance DAG execution engine with true parallel execution, built in Rust with Python bindings

Project description

graph-sp Python Bindings

Python bindings for the graph-sp DAG execution engine.

For complete documentation and installation instructions, visit the PyPI package page or the main repository.

Installation

pip install graph-sp

Quick Start

import graph_sp

# Create a graph
graph = graph_sp.Graph()

# Add nodes
graph.add_node(
    "source", "Data Source",
    [],  # no inputs
    [graph_sp.Port("output", "Numbers")],
    lambda inputs: {"output": [1, 2, 3, 4, 5]}
)

graph.add_node(
    "doubler", "Multiply by 2",
    [graph_sp.Port("input", "Input")],
    [graph_sp.Port("output", "Output")],
    lambda inputs: {"output": [x * 2 for x in inputs["input"]]}
)

# Connect and execute
graph.add_edge("source", "output", "doubler", "input")
executor = graph_sp.Executor()
result = executor.execute(graph)

print(result.get_output("doubler", "output"))  # [2, 4, 6, 8, 10]

Examples

This directory contains complete Python examples:

  • simple_pipeline.py: Basic 3-node pipeline with graph analysis and Mermaid diagrams
  • complex_objects.py: Demonstrates nested objects, JSON, and lists
  • parallel_execution.py: Shows parallel execution with 3 independent branches
  • implicit_edges.py: Demonstrates auto_connect() with parallel branches and multi-line labels

Running Examples

# Simple pipeline
python simple_pipeline.py

# Complex data structures
python complex_objects.py

# Parallel execution (shows 44% speedup)
python parallel_execution.py

# Implicit edge mapping
python implicit_edges.py

Features

  • True Parallel Execution: Independent nodes run concurrently (44% faster)
  • 🔌 Port-based Architecture: Type-safe data flow between nodes
  • 🔗 Implicit Edge Mapping: Auto-connect nodes by matching port names
  • 📊 Rich Data Types: Primitives, lists, nested dicts, JSON, binary data
  • 🔍 Graph Analysis: Depth, width, sources, sinks, and optimization suggestions
  • 🎨 Rich Mermaid Diagrams: Color-coded nodes, parallel group detection, multi-line labels
  • Cycle Detection: Built-in DAG validation

API Overview

Creating Graphs

import graph_sp

# Create a new graph
graph = graph_sp.Graph()

# Add a node with a Python function
graph.add_node(
    "node_id",           # Unique identifier
    "Node Name",         # Display name
    [                    # Input ports
        graph_sp.Port("input1", "First Input"),
        graph_sp.Port("input2", "Second Input")
    ],
    [                    # Output ports
        graph_sp.Port("output", "Result")
    ],
    lambda inputs: {     # Node function
        "output": inputs["input1"] + inputs["input2"]
    }
)

# Connect nodes
graph.add_edge("source_node", "output_port", "target_node", "input_port")

# OR use implicit edge mapping (auto-connect by port names)
edges_created = graph.auto_connect()  # No explicit add_edge() needed!

# Validate graph (checks for cycles)
graph.validate()

Implicit Edge Mapping (No add_edge() Needed!)

# Build graphs by matching port names automatically
graph = graph_sp.Graph()

# Add nodes with matching port names
graph.add_node("source", "Data Source", [],
    [graph_sp.Port("data", "Data")], source_fn)

graph.add_node("processor", "Processor",
    [graph_sp.Port("data", "Input")],  # Matches "data" output!
    [graph_sp.Port("result", "Result")], processor_fn)

graph.add_node("sink", "Sink",
    [graph_sp.Port("result", "Input")],  # Matches "result" output!
    [], sink_fn)

# Auto-connect based on port name matching
edges_created = graph.auto_connect()
print(f"✓ Created {edges_created} edges automatically!")

# Generated Mermaid diagram shows all connections:
# source -->|"data→data"| processor
# processor -->|"result→result"| sink

Executing Graphs

# Create executor
executor = graph_sp.Executor()

# Execute graph (automatically parallelizes independent nodes)
result = executor.execute(graph)

# Get outputs
value = result.get_output("node_id", "port_name")

Graph Analysis

# Analyze structure
analysis = graph.analyze()
print(f"Nodes: {analysis.node_count}")
print(f"Edges: {analysis.edge_count}")
print(f"Depth: {analysis.depth}")
print(f"Width: {analysis.width}")  # Parallelization potential
print(f"Sources: {analysis.source_count}")
print(f"Sinks: {analysis.sink_count}")

# Get text visualization
structure = graph.visualize()
print(structure)

# Generate Mermaid diagram
mermaid = graph.to_mermaid()
print(mermaid)

Mermaid Visualization with Parallel Groups

Multi-line labels and parallel execution groups are automatically detected:

# Example with parallel branches and multi-line labels
graph = graph_sp.Graph()

graph.add_node("source", "Value Source", [],
    [graph_sp.Port("value", "Value")], source_fn)

# Multi-line labels using \n
graph.add_node("branch_a", "Branch A\\n(×2)",
    [graph_sp.Port("value", "Input")],
    [graph_sp.Port("out_a", "Output")], branch_a_fn)

graph.add_node("branch_b", "Branch B\\n(+50)",
    [graph_sp.Port("value", "Input")],
    [graph_sp.Port("out_b", "Output")], branch_b_fn)

graph.add_node("merger", "Merger",
    [graph_sp.Port("out_a", "A"), graph_sp.Port("out_b", "B")],
    [], merger_fn)

graph.auto_connect()
mermaid = graph.to_mermaid()

Generated output:

graph TD
    source["Value Source"]
    style source fill:#e1f5ff,stroke:#01579b,stroke-width:2px
    branch_a["Branch A<br/>(×2)"]
    style branch_a fill:#fff3e0,stroke:#e65100,stroke-width:2px
    branch_b["Branch B<br/>(+50)"]
    style branch_b fill:#fff3e0,stroke:#e65100,stroke-width:2px
    merger["Merger"]
    style merger fill:#f3e5f5,stroke:#4a148c,stroke-width:2px

    %% Parallel Execution Groups Detected
    %% Group 1: 2 nodes executing in parallel

    subgraph parallel_group_1["⚡ Parallel Execution Group 1"]
        direction LR
        branch_b
        branch_a
    end
    style parallel_group_1 fill:#e8f5e9,stroke:#2e7d32,stroke-width:2px,stroke-dasharray: 5 5

    source -->|"value→value"| branch_a
    source -->|"value→value"| branch_b
    branch_a -->|"out_a→out_a"| merger
    branch_b -->|"out_b→out_b"| merger

Notice:

  • \n in node names becomes <br/> for proper line breaks
  • Parallel branches are grouped in a dashed green subgraph
  • Color-coded nodes: Blue (source), Orange (processing), Purple (sink)
  • All edges are properly connected (no disconnected nodes)

Data Types

All Python types are automatically converted:

Python Type graph-sp Type
int Int
float Float
str String
bool Bool
None None
list List
dict Map
JSON-serializable Json
bytes Bytes

Complex Data Structures

# Nested objects work seamlessly
user = {
    "name": "Alice",
    "age": 30,
    "address": {
        "city": "NYC",
        "zip": "10001"
    },
    "hobbies": ["reading", "coding", "hiking"]
}

# Lists of any type
numbers = [1, 2, 3, 4, 5]
mixed = [1, "hello", 3.14, True, None]

# JSON structures
product = {
    "id": "laptop-001",
    "specs": {
        "cpu": "Intel i7",
        "ram": "16GB"
    },
    "available": True,
    "price": 999.99
}

Parallel Execution

The executor automatically identifies and parallelizes independent branches:

# Fan-out pattern: 3 branches run in parallel
#
#         source
#        /  |  \
#     slow fast medium    <- Execute concurrently!
#        \  |  /
#        merger
#
# Sequential time: 900ms (500 + 100 + 300)
# Parallel time: 500ms (max branch time)
# Speedup: 44% faster!

graph = graph_sp.Graph()

graph.add_node("source", "Source", [], 
               [graph_sp.Port("value", "Value")],
               lambda _: {"value": 100})

# These 3 nodes will execute in parallel
graph.add_node("slow", "Slow Branch",
               [graph_sp.Port("input", "Input")],
               [graph_sp.Port("output", "Output")],
               lambda inputs: slow_operation(inputs["input"]))

graph.add_node("fast", "Fast Branch",
               [graph_sp.Port("input", "Input")],
               [graph_sp.Port("output", "Output")],
               lambda inputs: fast_operation(inputs["input"]))

graph.add_node("medium", "Medium Branch",
               [graph_sp.Port("input", "Input")],
               [graph_sp.Port("output", "Output")],
               lambda inputs: medium_operation(inputs["input"]))

# Connect all branches to source and merger
for branch in ["slow", "fast", "medium"]:
    graph.add_edge("source", "value", branch, "input")

Building from Source

If you want to build from source instead of using PyPI:

# Clone repository
git clone https://github.com/briday1/graph-sp.git
cd graph-sp

# Install maturin
pip install maturin

# Build and install
maturin develop --release --features python

Documentation

  • Full Documentation: https://github.com/briday1/graph-sp
  • Port Data Types: See docs/PORT_DATA_TYPES.md in the repository
  • Expected Output: See EXPECTED_OUTPUT.md in this directory

Performance

Measured with the parallel_execution.py example:

  • Sequential execution: ~900ms
  • Parallel execution: ~502ms
  • Speedup: 44% faster

The executor uses Rust's tokio runtime for true concurrent execution while properly managing Python's GIL.

License

MIT License

Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pygraph_sp-0.1.0.tar.gz (64.3 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pygraph_sp-0.1.0-cp312-cp312-win_amd64.whl (370.6 kB view details)

Uploaded CPython 3.12Windows x86-64

pygraph_sp-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (585.7 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

pygraph_sp-0.1.0-cp312-cp312-macosx_11_0_arm64.whl (505.1 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pygraph_sp-0.1.0-cp311-none-win_amd64.whl (170.0 kB view details)

Uploaded CPython 3.11Windows x86-64

pygraph_sp-0.1.0-cp311-cp311-manylinux_2_34_x86_64.whl (327.3 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

pygraph_sp-0.1.0-cp311-cp311-macosx_11_0_arm64.whl (236.3 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pygraph_sp-0.1.0-cp310-none-win_amd64.whl (170.0 kB view details)

Uploaded CPython 3.10Windows x86-64

pygraph_sp-0.1.0-cp310-cp310-manylinux_2_34_x86_64.whl (327.3 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

pygraph_sp-0.1.0-cp310-cp310-macosx_11_0_arm64.whl (236.3 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

pygraph_sp-0.1.0-cp39-none-win_amd64.whl (170.3 kB view details)

Uploaded CPython 3.9Windows x86-64

pygraph_sp-0.1.0-cp39-cp39-manylinux_2_34_x86_64.whl (327.9 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.34+ x86-64

pygraph_sp-0.1.0-cp39-cp39-macosx_11_0_arm64.whl (236.7 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

pygraph_sp-0.1.0-cp38-none-win_amd64.whl (170.2 kB view details)

Uploaded CPython 3.8Windows x86-64

pygraph_sp-0.1.0-cp38-cp38-manylinux_2_34_x86_64.whl (327.1 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.34+ x86-64

pygraph_sp-0.1.0-cp38-cp38-macosx_11_0_arm64.whl (236.4 kB view details)

Uploaded CPython 3.8macOS 11.0+ ARM64

File details

Details for the file pygraph_sp-0.1.0.tar.gz.

File metadata

  • Download URL: pygraph_sp-0.1.0.tar.gz
  • Upload date:
  • Size: 64.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pygraph_sp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0cad8fee49739e2deedf6dc4c1a46fdedc273d3038aff730fb7db557d2915671
MD5 a2d2335f0c39f4a3c70dc19e0b0a8b1d
BLAKE2b-256 4deadad2922c9ea78b5145474467aa08ee801f42f5a8933c3859a6d5564bc29d

See more details on using hashes here.

File details

Details for the file pygraph_sp-0.1.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: pygraph_sp-0.1.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 370.6 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pygraph_sp-0.1.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 bfbe813c59737745f4667e4228c07792a20cfd3ea60535a4648167d73a6f3dc3
MD5 251c8fe722e709a7c877fbe825b8859d
BLAKE2b-256 05dd57c9bb13630f618f8a84b9bc4f88fb7b9d76121b920b01ecf7ad821878be

See more details on using hashes here.

File details

Details for the file pygraph_sp-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pygraph_sp-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f1048fbc19682825fc80bd691b489d8f8287ae9c5903d859d2c843cef065074d
MD5 481092eadedcfee113f39b5d873f827b
BLAKE2b-256 1f4378828661ab5c3a4dacd90e92806b9ef9dede00ea42a01303a0ad8e82e1a0

See more details on using hashes here.

File details

Details for the file pygraph_sp-0.1.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pygraph_sp-0.1.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 32261a25875a02939f7747e47ab42c231460562bc49ad0c12528c68d4ff94426
MD5 27bc0c61695421e790639e54ac0e0ecf
BLAKE2b-256 2ec837689c39b49048129c3e93d1c50ef67fcbd914ea22b66a1674df971f8c72

See more details on using hashes here.

File details

Details for the file pygraph_sp-0.1.0-cp311-none-win_amd64.whl.

File metadata

  • Download URL: pygraph_sp-0.1.0-cp311-none-win_amd64.whl
  • Upload date:
  • Size: 170.0 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for pygraph_sp-0.1.0-cp311-none-win_amd64.whl
Algorithm Hash digest
SHA256 8db0d860765ad70b6a57e84212a46fadca4fb18315c2d6a1ced883f64dc218da
MD5 d31147ddb9eb31158892c138acf3db30
BLAKE2b-256 eb493f551b32c6f63f661538e86d7ed925f1b144d14648ccc6dd1b8507f0e8d2

See more details on using hashes here.

File details

Details for the file pygraph_sp-0.1.0-cp311-cp311-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for pygraph_sp-0.1.0-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 fc90f619193b3e5cd6a27577339436de302dd4a9599aeffe6641c30bd380f35a
MD5 abfb304b7fbf4ed185d2922b8ef121b7
BLAKE2b-256 d483fd82e8f60f503028430f2d96fbee6043ddbceeb0bcb82032daf6910dde76

See more details on using hashes here.

File details

Details for the file pygraph_sp-0.1.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pygraph_sp-0.1.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3ab7a3d6a055e9029a8355f715fc38ef33cd3aa6a9a6c5219c15372725971640
MD5 e6c564ea1e5b3b0127c7523038349e03
BLAKE2b-256 8aa915251fa504da6437a83273105145594ec5b8623ab4008080fe885f40778f

See more details on using hashes here.

File details

Details for the file pygraph_sp-0.1.0-cp310-none-win_amd64.whl.

File metadata

  • Download URL: pygraph_sp-0.1.0-cp310-none-win_amd64.whl
  • Upload date:
  • Size: 170.0 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for pygraph_sp-0.1.0-cp310-none-win_amd64.whl
Algorithm Hash digest
SHA256 41e50ddb87bc59dc69b18dc2fb8e421a89b5d9d457bb2317d0017fbfdda716f5
MD5 061e0893572cafa96320cbb1a14f5eca
BLAKE2b-256 6dd7d499451422dd3d885edd75b8098f5eab1ed1447c631a74dad6259e5ae96c

See more details on using hashes here.

File details

Details for the file pygraph_sp-0.1.0-cp310-cp310-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for pygraph_sp-0.1.0-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 bac7cf7ddf4b84f40c987fc3c69737942bfadf43c2554992c4e7aa0db292eb9d
MD5 3f0a228c585fe9d9a03f38d4b4bd85aa
BLAKE2b-256 b793c8d59bc78e3d3bc458f783033d5c17cbfea23d280d7ac5784481ca52f645

See more details on using hashes here.

File details

Details for the file pygraph_sp-0.1.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pygraph_sp-0.1.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 24df55a5f75e80a45dc2a6bc8796236a2d6f2593c5c0c026b80527963258f738
MD5 ead9a0d2f18841679d6b1de79ea0f2a2
BLAKE2b-256 caa42e3e026151bbaf2573e6b99a4c50478ee1298c0509a60e5c70b0f404fce4

See more details on using hashes here.

File details

Details for the file pygraph_sp-0.1.0-cp39-none-win_amd64.whl.

File metadata

  • Download URL: pygraph_sp-0.1.0-cp39-none-win_amd64.whl
  • Upload date:
  • Size: 170.3 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for pygraph_sp-0.1.0-cp39-none-win_amd64.whl
Algorithm Hash digest
SHA256 3e4425ebec0f611b8a8642d8040815c5faca8102dca38bb2324ae00bc695ea80
MD5 34e0fb65d519e8beb58d87e3f4d44c53
BLAKE2b-256 cdfad5888295f5b003fe76fb1e9bd0d32e9c04185abf481284defca96801b38e

See more details on using hashes here.

File details

Details for the file pygraph_sp-0.1.0-cp39-cp39-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for pygraph_sp-0.1.0-cp39-cp39-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 a2aee05ed1ea0d01a42a1226cdb523e695de738ce192ce22b39f535c73dc009e
MD5 20d39f2b64281c834dc61b98e092b26c
BLAKE2b-256 e0273e8d7517d369a4ea21631bf0b845180a9e5197913f5b48fa2c7c9327b42e

See more details on using hashes here.

File details

Details for the file pygraph_sp-0.1.0-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pygraph_sp-0.1.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6d392241640211ad96022972e8cf975d56928cd0fc7955fe5791c4988a467738
MD5 b18459eeee41ffbe89ae37478d736c4c
BLAKE2b-256 c7893fe66474f19bd3eeb9895c8cb90480abb4e650870e9a89b73a52b8875753

See more details on using hashes here.

File details

Details for the file pygraph_sp-0.1.0-cp38-none-win_amd64.whl.

File metadata

  • Download URL: pygraph_sp-0.1.0-cp38-none-win_amd64.whl
  • Upload date:
  • Size: 170.2 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for pygraph_sp-0.1.0-cp38-none-win_amd64.whl
Algorithm Hash digest
SHA256 1b93636b8f5d70320f76f5367c42b638c73ac5b0c23857b9643748a7197f0460
MD5 84fa8b69b07190143b2b5ad7b655b44c
BLAKE2b-256 97a2d6459e289e36dd8c2cbc8162da07f9837d6f66aea862e67a3a33be8b0180

See more details on using hashes here.

File details

Details for the file pygraph_sp-0.1.0-cp38-cp38-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for pygraph_sp-0.1.0-cp38-cp38-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 38861be8e55e891017155bed473c92ca8afe6bf79d69a8a7d34eff1180006cf6
MD5 e4a937ced9a8bc29a200df48f5f1d62c
BLAKE2b-256 99388824ab3cd08c2dd186ae9699dade6ea7aad965846b3b7f6e782b0b9c44ac

See more details on using hashes here.

File details

Details for the file pygraph_sp-0.1.0-cp38-cp38-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pygraph_sp-0.1.0-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1d8b384954d895aba527908f842e01074d9735856712b20354f93e9e1d4ead54
MD5 5e2fa3ccb0947e9c557ca6c69f3aa801
BLAKE2b-256 2a5a2f87f31c9b0e21f2ec75da93a5092223961cf30233733047f957132dafc6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page