intrepid-python-sdk


Nameintrepid-python-sdk JSON
Version 0.1.10 PyPI version JSON
download
home_pageNone
SummaryIntrepid Python SDK
upload_time2024-12-17 20:21:47
maintainerNone
docs_urlNone
authorfrag
requires_python>=3.7
licenseApache License Version 2.0
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Build and Install


Create a new conda environment with `conda create -n intrepid python=3.10`

Activate environment with

```
conda activate intrepid
```

Install `poetry` with `pip install poetry` and all requirements `pip install -r requirements.txt`

Build Python Intrepid SDK

```Bash
poetry build
poetry install
```
And check that all has been installed correctly

```
python examples/ex0.py
```

This should print

```
Hello from Intrepid SDK
```


<!-- `python3 -m websockets ws://localhost:9999/` -->



# Example for showcasing Python bindings

## Create Python Node

A Python node is created from dashboard and rendered according to the Python function signature that is attached.

A Python SDK allows to
1. read from the output of a node and
2. write to the input of a node.

Rendering a node means defining inputs and outputs complete with types (only primitive types supported).

```python
from intrepid_python_sdk import Intrepid, Qos, Node, Type, IntrepidType
import time


# Callback function to execute when inputs are ready
def my_callback_function(in1: int, in2:int) -> (float, bool):
    # Add code here
    time.sleep(0.5)
    return 1. * (in1 + in2), True


# Create QoS policy for function node
qos = Qos(reliability="BestEffort", durability="TransientLocal")
qos.set_history("KeepLast")
qos.set_deadline(100)  # Deadline expressed in milliseconds


# Create my node
node_type = "node/sdk/2-node"
mynode = Node(node_type)
mynode.add_input("flow", IntrepidType(Type.FLOW))
mynode.add_input("in1", IntrepidType(Type.INTEGER))
mynode.add_input("in2", IntrepidType(Type.INTEGER))
mynode.add_output("flow", IntrepidType(Type.FLOW))
mynode.add_output("out1", IntrepidType(Type.FLOAT))
mynode.add_output("is_float", IntrepidType(Type.BOOLEAN))

# Write to Graph
service_handler = Intrepid()
service_handler.register_node(mynode)

# Attach Qos policy to this node
service_handler.create_qos(qos)

# Register callback with node input. Callback and node inputs must have the same signature (same number/name/type)
service_handler.register_callback(lambda: my_callback_function)

# Start server and node execution
service_handler.start()
```

`node_id`, `input_id`, `output_id` are in the property section of the sidebar of the relative nodes.



## Create Node

A node in the Intrepid platform is a fundamental building block that represents a logical function, package, or module capable of performing computation on inputs and making results available on outputs. In the context of visual programming tools provided by Intrepid, a node is a block that users can drag and drop in the editor and connect with other nodes to create workflows or pipelines.

From a developer’s perspective, a node can be thought of as a container for custom logic implemented in Python, Rust, C/C++. Users who want to implement their own custom logic can create a node using Python, add their desired functionality, and publish it to the Intrepid graph. Once published, these custom nodes can be seamlessly integrated into the visual programming environment, allowing users to connect them with other nodes just like any other built-in node.

In summary, a node in Intrepid serves as a modular unit for encapsulating computational logic, enabling users to create custom functionalities and extend the capabilities of the platform’s visual programming tools.

An example node with 3 inputs and 3 outputs is provided below

```Python
# Create my node
mynode = Node("my_type")
mynode.add_input("flow", IntrepidType(Type.FLOW))
mynode.add_input("in1", IntrepidType(Type.INTEGER))
mynode.add_input("in2", IntrepidType(Type.INTEGER))
mynode.add_output("flow", IntrepidType(Type.FLOW))
mynode.add_output("out1", IntrepidType(Type.FLOAT))
mynode.add_output("is_float", IntrepidType(Type.BOOLEAN))
```


## Register Node

Once a node has been created with its desired logic implemented, it must be registered with the Intrepid engine to become operational within the platform’s ecosystem. Registration involves associating the node with the Intrepid engine, enabling it to be recognized and utilized by other components of the system.

After registration, the user needs to attach a callback function to the node. This callback function defines the specific actions or computations the node will perform when inputs are received. The callback function typically takes input data, processes it, and generates output data accordingly.

Once the callback function is attached, the node is ready to start executing its logic. Starting the node initiates its operation within the Intrepid environment, allowing it to actively process inputs, execute the defined logic, and produce output data as per its functionality.

Below is an example demonstrating the process of registering, attaching a callback, and starting a node in Python using the Python SDK:


```Python
# Write to Graph
node_handler = Intrepid(node_id="node_type/node_id")
node_handler.register_node(mynode)

# Attach Qos policy to this node
node_handler.create_qos(qos)
```
​
## Register Callback and Start Node

```Python
# Register callback with node input. Callback and node inputs must have the same signature (same number/name/type)
node_handler.register_callback(my_callback_function)

# Start server and node execution
node_handler.start()
```

This should show node info and status

```Bash
Created node  node/sdk/ex1
Attached QoS policy to node
Callback registered to node
Listening on host 127.0.0.1:9999

```

Node `node/sdk/ex1` is running a websocket server at `127.0.0.1:9999`



## Start Intrepid Runtime Core

Execute the Intrepid runtime (`intrepid-agent`) with arguments
`run-node` <node_name>
`--load ws://<host>:<port>` where the node is running
`-i input1`
`-i input2`


```Bash
./intrepid-agent run-node node/sdk/ex1 --load ws://127.0.0.1:9999 -i 1 -i 2
```

This should show

```Bash
2024-10-08T14:18:42.078Z INFO  [exec_graph_connector::plugins] remote plugin initialized: ws://127.0.0.1:9999
2024-10-08T14:18:42.104Z INFO  [exec_graph_connector::plugins] remote plugin initialized: ws://127.0.0.1:9999
2024-10-08T14:18:42.607Z INFO  [exec_graph_connector::agent_task] 3.0

```

The node is running and computing the callback function, and returning `3.0`

## Publish custom node

In order to be viewed from the dashboard and connected to the rest of the graph, a node must be published.
An authentication token is necessary to publish a node to a user library. Such token can be retrieved from dashboard at https://labs.intrepid.ai from the `Project` section on the left sidebar.


```Bash
./intrepid-agent publish node/sdk/ex1 --load ws://127.0.0.1:9999 https://labs.intrepid.ai/projects/34/r3Gv...otpm

```

If node is published correctly, this will be printed to stdout

```Bash
intrepid.ai/projects/34/Uy66ce2RCqqOniGLBuNGcaUu
2024-10-08T15:15:28.790Z INFO  [exec_graph_connector::plugins] remote plugin initialized: ws://127.0.0.1:9999
2024-10-08T15:15:28.795Z INFO  [exec_graph_connector::http] -> https://labs.intrepid.ai/api/nodes/sdk
2024-10-08T15:15:28.833Z INFO  [exec_graph_connector::http] <- 201, length: 43
```


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "intrepid-python-sdk",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": null,
    "author": "frag",
    "author_email": "francesco@intrepid.ai",
    "download_url": "https://files.pythonhosted.org/packages/b8/79/be4182e39465a1e6118561e4d42de0479a8a602f5774873db9d422e7091e/intrepid_python_sdk-0.1.10.tar.gz",
    "platform": null,
    "description": "# Build and Install\n\n\nCreate a new conda environment with `conda create -n intrepid python=3.10`\n\nActivate environment with\n\n```\nconda activate intrepid\n```\n\nInstall `poetry` with `pip install poetry` and all requirements `pip install -r requirements.txt`\n\nBuild Python Intrepid SDK\n\n```Bash\npoetry build\npoetry install\n```\nAnd check that all has been installed correctly\n\n```\npython examples/ex0.py\n```\n\nThis should print\n\n```\nHello from Intrepid SDK\n```\n\n\n<!-- `python3 -m websockets ws://localhost:9999/` -->\n\n\n\n# Example for showcasing Python bindings\n\n## Create Python Node\n\nA Python node is created from dashboard and rendered according to the Python function signature that is attached.\n\nA Python SDK allows to\n1. read from the output of a node and\n2. write to the input of a node.\n\nRendering a node means defining inputs and outputs complete with types (only primitive types supported).\n\n```python\nfrom intrepid_python_sdk import Intrepid, Qos, Node, Type, IntrepidType\nimport time\n\n\n# Callback function to execute when inputs are ready\ndef my_callback_function(in1: int, in2:int) -> (float, bool):\n    # Add code here\n    time.sleep(0.5)\n    return 1. * (in1 + in2), True\n\n\n# Create QoS policy for function node\nqos = Qos(reliability=\"BestEffort\", durability=\"TransientLocal\")\nqos.set_history(\"KeepLast\")\nqos.set_deadline(100)  # Deadline expressed in milliseconds\n\n\n# Create my node\nnode_type = \"node/sdk/2-node\"\nmynode = Node(node_type)\nmynode.add_input(\"flow\", IntrepidType(Type.FLOW))\nmynode.add_input(\"in1\", IntrepidType(Type.INTEGER))\nmynode.add_input(\"in2\", IntrepidType(Type.INTEGER))\nmynode.add_output(\"flow\", IntrepidType(Type.FLOW))\nmynode.add_output(\"out1\", IntrepidType(Type.FLOAT))\nmynode.add_output(\"is_float\", IntrepidType(Type.BOOLEAN))\n\n# Write to Graph\nservice_handler = Intrepid()\nservice_handler.register_node(mynode)\n\n# Attach Qos policy to this node\nservice_handler.create_qos(qos)\n\n# Register callback with node input. Callback and node inputs must have the same signature (same number/name/type)\nservice_handler.register_callback(lambda: my_callback_function)\n\n# Start server and node execution\nservice_handler.start()\n```\n\n`node_id`, `input_id`, `output_id` are in the property section of the sidebar of the relative nodes.\n\n\n\n## Create Node\n\nA node in the Intrepid platform is a fundamental building block that represents a logical function, package, or module capable of performing computation on inputs and making results available on outputs. In the context of visual programming tools provided by Intrepid, a node is a block that users can drag and drop in the editor and connect with other nodes to create workflows or pipelines.\n\nFrom a developer\u2019s perspective, a node can be thought of as a container for custom logic implemented in Python, Rust, C/C++. Users who want to implement their own custom logic can create a node using Python, add their desired functionality, and publish it to the Intrepid graph. Once published, these custom nodes can be seamlessly integrated into the visual programming environment, allowing users to connect them with other nodes just like any other built-in node.\n\nIn summary, a node in Intrepid serves as a modular unit for encapsulating computational logic, enabling users to create custom functionalities and extend the capabilities of the platform\u2019s visual programming tools.\n\nAn example node with 3 inputs and 3 outputs is provided below\n\n```Python\n# Create my node\nmynode = Node(\"my_type\")\nmynode.add_input(\"flow\", IntrepidType(Type.FLOW))\nmynode.add_input(\"in1\", IntrepidType(Type.INTEGER))\nmynode.add_input(\"in2\", IntrepidType(Type.INTEGER))\nmynode.add_output(\"flow\", IntrepidType(Type.FLOW))\nmynode.add_output(\"out1\", IntrepidType(Type.FLOAT))\nmynode.add_output(\"is_float\", IntrepidType(Type.BOOLEAN))\n```\n\n\n## Register Node\n\nOnce a node has been created with its desired logic implemented, it must be registered with the Intrepid engine to become operational within the platform\u2019s ecosystem. Registration involves associating the node with the Intrepid engine, enabling it to be recognized and utilized by other components of the system.\n\nAfter registration, the user needs to attach a callback function to the node. This callback function defines the specific actions or computations the node will perform when inputs are received. The callback function typically takes input data, processes it, and generates output data accordingly.\n\nOnce the callback function is attached, the node is ready to start executing its logic. Starting the node initiates its operation within the Intrepid environment, allowing it to actively process inputs, execute the defined logic, and produce output data as per its functionality.\n\nBelow is an example demonstrating the process of registering, attaching a callback, and starting a node in Python using the Python SDK:\n\n\n```Python\n# Write to Graph\nnode_handler = Intrepid(node_id=\"node_type/node_id\")\nnode_handler.register_node(mynode)\n\n# Attach Qos policy to this node\nnode_handler.create_qos(qos)\n```\n\u200b\n## Register Callback and Start Node\n\n```Python\n# Register callback with node input. Callback and node inputs must have the same signature (same number/name/type)\nnode_handler.register_callback(my_callback_function)\n\n# Start server and node execution\nnode_handler.start()\n```\n\nThis should show node info and status\n\n```Bash\nCreated node  node/sdk/ex1\nAttached QoS policy to node\nCallback registered to node\nListening on host 127.0.0.1:9999\n\n```\n\nNode `node/sdk/ex1` is running a websocket server at `127.0.0.1:9999`\n\n\n\n## Start Intrepid Runtime Core\n\nExecute the Intrepid runtime (`intrepid-agent`) with arguments\n`run-node` <node_name>\n`--load ws://<host>:<port>` where the node is running\n`-i input1`\n`-i input2`\n\n\n```Bash\n./intrepid-agent run-node node/sdk/ex1 --load ws://127.0.0.1:9999 -i 1 -i 2\n```\n\nThis should show\n\n```Bash\n2024-10-08T14:18:42.078Z INFO  [exec_graph_connector::plugins] remote plugin initialized: ws://127.0.0.1:9999\n2024-10-08T14:18:42.104Z INFO  [exec_graph_connector::plugins] remote plugin initialized: ws://127.0.0.1:9999\n2024-10-08T14:18:42.607Z INFO  [exec_graph_connector::agent_task] 3.0\n\n```\n\nThe node is running and computing the callback function, and returning `3.0`\n\n## Publish custom node\n\nIn order to be viewed from the dashboard and connected to the rest of the graph, a node must be published.\nAn authentication token is necessary to publish a node to a user library. Such token can be retrieved from dashboard at https://labs.intrepid.ai from the `Project` section on the left sidebar.\n\n\n```Bash\n./intrepid-agent publish node/sdk/ex1 --load ws://127.0.0.1:9999 https://labs.intrepid.ai/projects/34/r3Gv...otpm\n\n```\n\nIf node is published correctly, this will be printed to stdout\n\n```Bash\nintrepid.ai/projects/34/Uy66ce2RCqqOniGLBuNGcaUu\n2024-10-08T15:15:28.790Z INFO  [exec_graph_connector::plugins] remote plugin initialized: ws://127.0.0.1:9999\n2024-10-08T15:15:28.795Z INFO  [exec_graph_connector::http] -> https://labs.intrepid.ai/api/nodes/sdk\n2024-10-08T15:15:28.833Z INFO  [exec_graph_connector::http] <- 201, length: 43\n```\n\n",
    "bugtrack_url": null,
    "license": "Apache License Version 2.0",
    "summary": "Intrepid Python SDK",
    "version": "0.1.10",
    "project_urls": {
        "Documentation": "https://docs.developers.intrepid.ai/docs/python",
        "Sources": "https://github.com/IntrepidAI/intrepid-python-sdk"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6971dd93afe260eee00f07a870221eb78a2510f087ceb5505fbc4c4592ec7cf7",
                "md5": "07734c9a21189013f5f7eb3867117433",
                "sha256": "b73e3efd9da8d0ad15d03a84430fd98cc7d73ba334828e0034c75c1a1fb3a40e"
            },
            "downloads": -1,
            "filename": "intrepid_python_sdk-0.1.10-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "07734c9a21189013f5f7eb3867117433",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 25945,
            "upload_time": "2024-12-17T20:21:44",
            "upload_time_iso_8601": "2024-12-17T20:21:44.752647Z",
            "url": "https://files.pythonhosted.org/packages/69/71/dd93afe260eee00f07a870221eb78a2510f087ceb5505fbc4c4592ec7cf7/intrepid_python_sdk-0.1.10-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b879be4182e39465a1e6118561e4d42de0479a8a602f5774873db9d422e7091e",
                "md5": "a6b6a76205f206347b865687984ee08b",
                "sha256": "3f7e5f91e031d43a0733b3f00158746143490aebcbfd45ddb7d768b78b8a859b"
            },
            "downloads": -1,
            "filename": "intrepid_python_sdk-0.1.10.tar.gz",
            "has_sig": false,
            "md5_digest": "a6b6a76205f206347b865687984ee08b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 24126,
            "upload_time": "2024-12-17T20:21:47",
            "upload_time_iso_8601": "2024-12-17T20:21:47.195664Z",
            "url": "https://files.pythonhosted.org/packages/b8/79/be4182e39465a1e6118561e4d42de0479a8a602f5774873db9d422e7091e/intrepid_python_sdk-0.1.10.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-17 20:21:47",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "IntrepidAI",
    "github_project": "intrepid-python-sdk",
    "github_not_found": true,
    "lcname": "intrepid-python-sdk"
}
        
Elapsed time: 0.38966s