### Bash: Install Dependencies and Start Development Server Source: https://github.com/linkdlab/funcnodes/blob/main/docs/content/extending/react-plugins.md Commands to set up the React plugin development environment. It involves navigating to the `react_plugin` directory, installing Node.js dependencies, and starting the development server in watch mode for continuous rebuilding. ```bash cd react_plugin npm install npm run dev # Watch mode ``` -------------------------------- ### Installing and Testing a FuncNodes Module Source: https://github.com/linkdlab/funcnodes/blob/main/docs/content/extending/writing-modules.md Provides the commands to install a FuncNodes module in development mode, list installed modules, and start the FuncNodes server for testing. ```bash # Install in development mode pip install -e . # Verify discovery funcnodes modules list # Should show: funcnodes_mymodule # Test in the UI funcnodes runserver ``` -------------------------------- ### Display FuncNodes CLI Help Source: https://github.com/linkdlab/funcnodes/blob/main/docs/content/api/cli.md Shows all available commands and their usage for the FuncNodes CLI. This is a standard help command and requires no specific setup. ```bash funcnodes --help ``` -------------------------------- ### Verify FuncNodes Installation Source: https://github.com/linkdlab/funcnodes/blob/main/docs/content/getting-started/installation.md Checks if FuncNodes has been installed correctly by displaying its version number. This command should be run in the terminal after installation. ```bash funcnodes --version ``` -------------------------------- ### Start FuncNodes Web UI Server (Bash) Source: https://github.com/linkdlab/funcnodes/blob/main/docs/content/api/cli.md This command starts the FuncNodes web UI server, which serves static files for browser interaction. It defaults to 'localhost:8000' and automatically opens a browser window. The server attempts to connect to or spawn a Workermanager instance. ```bash funcnodes [common_options] runserver [server_options] ``` -------------------------------- ### Start Workermanager (Bash) Source: https://github.com/linkdlab/funcnodes/blob/main/docs/content/api/cli.md Starts the Workermanager via the CLI. Optional arguments allow specifying the host and port, defaulting to values defined in the config. ```bash funcnodes [common_options] startworkermanager [workermanager_options] ``` -------------------------------- ### Install and Run FuncNodes CLI Source: https://github.com/linkdlab/funcnodes/blob/main/docs/content/index.md This snippet shows the basic commands to install FuncNodes using pip and to launch the local development server. The server is typically accessed via a web browser. ```bash pip install funcnodes # Install funcnodes runserver # Launch UI at localhost:8000 ``` -------------------------------- ### Starting Funcnodes Server (Bash) Source: https://github.com/linkdlab/funcnodes/blob/main/README.md Provides the bash command to start the Funcnodes web server. This server enables a browser-based user interface for visualizing and interacting with the Funcnodes system. ```bash funcnodes runserver ``` -------------------------------- ### Starting a Funcnodes Worker (Bash) Source: https://github.com/linkdlab/funcnodes/blob/main/README.md Demonstrates how to start a specific worker process via the Funcnodes CLI, using either its name or UUID for identification. ```bash funcnodes worker start --name= --uuid= ``` -------------------------------- ### List All Workers (Full Output) Source: https://github.com/linkdlab/funcnodes/blob/main/docs/content/api/cli.md Retrieves a detailed list of all workers, including their full configuration dictionaries. This requires the --full option and provides comprehensive information about each worker's setup and dependencies. ```bash funcnodes [common_options] worker list --full ``` -------------------------------- ### Start FuncNodes Web Server (CLI) Source: https://context7.com/linkdlab/funcnodes/llms.txt Starts the FuncNodes web server for visual workflow management. Supports custom host, port, and configuration directories, as well as debug logging. The server can optionally open the browser automatically. ```bash # Basic server start (opens browser automatically) funcnodes runserver # Custom host and port funcnodes runserver --host 0.0.0.0 --port 9000 # Without automatic browser opening funcnodes runserver --no-browser # Custom configuration directory funcnodes --dir ./my_project/.funcnodes runserver # Enable debug logging funcnodes --debug runserver ``` -------------------------------- ### Install Funcnodes Package Source: https://github.com/linkdlab/funcnodes/blob/main/README.md This command installs the Funcnodes package using pip. Ensure Python 3.8 or higher and pip are installed prerequisites. This is the primary step for setting up Funcnodes. ```bash pip install funcnodes ``` -------------------------------- ### Install Docs Tooling with UV Source: https://github.com/linkdlab/funcnodes/blob/main/CONTRIBUTING.md Installs the necessary tooling for building and serving documentation for FuncNodes using uv. This command synchronizes dependencies specifically for the 'docs' group. It requires changing into the FuncNodes directory and setting the UV cache directory. ```bash cd FuncNodes UV_CACHE_DIR=.cache/uv uv sync --group docs ``` -------------------------------- ### Install Specific FuncNodes Version with Pip Source: https://github.com/linkdlab/funcnodes/blob/main/docs/content/getting-started/installation.md Installs a specific version of the FuncNodes Python package using pip. This is useful for ensuring compatibility with older projects or for testing. Replace '0.5' with the desired version number. ```bash pip install funcnodes=="0.5" ``` -------------------------------- ### Start a Funcnodes Worker via CLI Source: https://github.com/linkdlab/funcnodes/blob/main/docs/content/api/cli.md This command starts an existing worker process using the Funcnodes CLI. The worker will run continuously until manually stopped. It's important to note that a worker can only run one instance at a time. ```bash funcnodes [common_options] worker --uuid|--name start ``` -------------------------------- ### List Installed FuncNodes Modules (CLI) Source: https://context7.com/linkdlab/funcnodes/llms.txt Lists all available FuncNodes modules in the current environment. ```bash funcnodes modules list ``` -------------------------------- ### Starting Funcnodes Worker Manager (Bash) Source: https://github.com/linkdlab/funcnodes/blob/main/README.md Shows the bash command to manually start the Funcnodes WorkerManager. This component handles WebSocket connections between the web interface and the backend, managing worker processes that execute node functionalities. ```bash funcnodes startworkermanager ``` -------------------------------- ### Example Worker Configuration JSON Source: https://github.com/linkdlab/funcnodes/blob/main/docs/content/architecture/worker-components.md Provides an example of a worker configuration file in JSON format. This illustrates how to specify worker details like UUID, name, paths, network settings, startup behavior, and package dependencies. ```json { "uuid": "abc123", "name": "my-workflow", "data_path": "~/.funcnodes/workers/worker_my-workflow", "env_path": "~/.funcnodes/workers/worker_my-workflow/.venv", "host": "localhost", "port": 9382, "ssl": false, "update_on_startup": { "funcnodes": true, "funcnodes-core": true }, "package_dependencies": { "funcnodes-numpy": { "package": "funcnodes-numpy", "version": ">=0.2.0" } }, "workertype": "WSWorker" } ``` -------------------------------- ### Install Pre-commit Hooks with UV Source: https://github.com/linkdlab/funcnodes/blob/main/CONTRIBUTING.md Installs pre-commit hooks for code style checking in the FuncNodes project using uv. This command ensures that code formatting and linting checks are set up locally before committing. It requires navigating to the FuncNodes directory and setting the UV cache directory. ```bash cd FuncNodes UV_CACHE_DIR=.cache/uv uv run pre-commit install ``` -------------------------------- ### Decorator-Based Nodes Example Source: https://github.com/linkdlab/funcnodes/blob/main/docs/content/components/nodeinput.md Illustrates how inputs are automatically created from function parameters when using `fn.NodeDecorator`. ```APIDOC ## Decorator-Based Nodes ### Description Shows how `funcnodes` automatically infers `NodeInput` parameters from a decorated function's signature. ### Usage ```python @fn.NodeDecorator(node_id="add_numbers") def add(a: int = 0, b: int = 0) -> int: return a + b ``` ### Explanation When the `@fn.NodeDecorator` is applied to the `add` function: - An input named `a` is created with type hint `int` and a default value of `0`. - An input named `b` is created with type hint `int` and a default value of `0`. - The return type hint (`-> int`) might influence output node configuration, though not explicitly detailed here. ``` -------------------------------- ### Launch FuncNodes Server Source: https://github.com/linkdlab/funcnodes/blob/main/docs/content/getting-started/basic_usage.md Starts the FuncNodes web interface. This command launches the server, allowing access to the FuncNodes UI in a web browser. Additional options can be found in the CLI reference. ```bash funcnodes runserver # (1)! ``` -------------------------------- ### Get Worker Dependencies Source: https://github.com/linkdlab/funcnodes/blob/main/docs/content/architecture/message-protocol.md Retrieves a list of installed package dependencies for the worker. ```APIDOC ## GET /get_worker_dependencies ### Description Get installed package dependencies. ### Method GET ### Endpoint /get_worker_dependencies ### Parameters #### Query Parameters - **cmd** (string) - Required - Must be "get_worker_dependencies" ### Request Example ```json { "type": "cmd", "cmd": "get_worker_dependencies" } ``` ### Response #### Success Response (200) - **type** (string) - "result" - **cmd** (string) - "get_worker_dependencies" - **result** (object) - A dictionary of installed packages and their versions. - **package_name** (object) - **package** (string) - The name of the package. - **version** (string) - The installed version of the package. #### Response Example ```json { "type": "result", "cmd": "get_worker_dependencies", "result": { "funcnodes-basic": {"package": "funcnodes-basic", "version": "0.2.1"}, "funcnodes-numpy": {"package": "funcnodes-numpy", "version": "0.2.5"} } } ``` ``` -------------------------------- ### Get Worker Dependencies (JSON) Source: https://github.com/linkdlab/funcnodes/blob/main/docs/content/architecture/message-protocol.md Retrieves a list of all installed package dependencies for the worker, including their package names and versions. This is a read-only command. ```json { "type": "cmd", "cmd": "get_worker_dependencies" } ``` -------------------------------- ### Check FuncNodes Version Source: https://github.com/linkdlab/funcnodes/blob/main/docs/content/api/cli.md Verifies if the FuncNodes CLI is installed and accessible by printing its current version. No specific dependencies are required for this check. ```bash funcnodes --version ``` -------------------------------- ### Programmatic Node Usage in Funcnodes (Python) Source: https://github.com/linkdlab/funcnodes/blob/main/README.md Demonstrates how to programmatically instantiate, configure, and await a Funcnodes Node. It shows setting input values, checking readiness to trigger, monitoring trigger status, and retrieving output values asynchronously. This is useful for testing and understanding node behavior. ```python from funcnodes.basic_nodes.math import add_node async def main(): add_node_ins = Adadd_nodedNode() # generate Node instance that does a, b: a+b add_node_ins.inputs["a"].value = 1 # sets the input of a to 1 # since add_node requires both inputs to be set, nothing happens # node is not ready to trigger: print("ready2trigger",add_node_ins.ready_to_trigger()) # an is also not currently in trigger: print("in_trigger",add_node_ins.in_trigger) add_node_ins.inputs["b"].value = 3 # node is not ready to trigger: print("ready2trigger",add_node_ins.ready_to_trigger()) # since it is currently in trigger: print("in_trigger",add_node_ins.in_trigger) # since it is still triggering the output is not set: print("out", add_node_ins.outputs["out"].value) # wait fot the actuall trigger process await add_node_ins # now the output is as expected print("out", 5) ... # call asyinc main function. ``` -------------------------------- ### Activate Worker Virtual Environment (Bash) Source: https://github.com/linkdlab/funcnodes/blob/main/docs/content/api/cli.md Activates the virtual environment of a specified worker. This is primarily for debugging or manual package installation within the worker's isolated environment. ```bash funcnodes [common_options] worker --uuid|--name activate >> funcnodes worker --name dummy activate (worker_c52079f077f94929908bbc9013941a08)>>█ ``` -------------------------------- ### Serve Docs Locally with MkDocs Source: https://github.com/linkdlab/funcnodes/blob/main/CONTRIBUTING.md Serves the FuncNodes documentation locally using MkDocs. This command requires the documentation tooling to be installed and specifies the MkDocs configuration file. It utilizes uv to run the mkdocs serve command, ensuring dependencies are met. ```bash cd FuncNodes UV_CACHE_DIR=.cache/uv uv run mkdocs serve -f docs/mkdocs.yml ``` -------------------------------- ### Create Custom External Worker in Python Source: https://github.com/linkdlab/funcnodes/blob/main/docs/content/architecture/worker-components.md Define a custom worker by subclassing ExternalWorker. This allows for additional capabilities and custom RPC command handling. The worker type is specified via the `worker_type` attribute, and custom setup logic can be implemented in the `setup` method. Custom RPC commands are handled by methods starting with `handle_custom_command`. ```python from funcnodes_worker import ExternalWorker class MyCustomWorker(ExternalWorker): """Custom worker with additional capabilities.""" worker_type = "my_custom_worker" async def setup(self): """Called during worker initialization.""" await super().setup() # Custom setup logic async def handle_custom_command(self, **kwargs): """Custom RPC command.""" return {"custom": "result"} ``` -------------------------------- ### Run FuncNodes Server in Development Mode Source: https://github.com/linkdlab/funcnodes/blob/main/docs/content/getting-started/basic_usage.md Launches the FuncNodes server while keeping data within the project folder, which is useful for developing custom nodes. This command directs FuncNodes to use a local directory for data storage. ```bash funcnodes --dir .funcnodes runserver ``` -------------------------------- ### Run FuncNodes in Profiling Mode Source: https://github.com/linkdlab/funcnodes/blob/main/docs/content/api/cli.md Executes a FuncNodes task under profiling mode using the 'yappi' library. This requires FuncNodes to be installed with the optional 'fundnodes[profiling]' dependency. It generates a 'funcnodesprofile.pstat' file for analysis. ```bash funcnodes --profile {task} ``` -------------------------------- ### Customize FuncNodes Web UI Port Source: https://github.com/linkdlab/funcnodes/blob/main/docs/content/ui-guide/react_flow/web-ui.md Command to start the FuncNodes web server on a custom port. This allows users to avoid port conflicts or use a preferred port. For example, to use port 8080: ```bash funcnodes runserver --port 8080 ``` -------------------------------- ### Worker Tasks: Management and Interaction Source: https://github.com/linkdlab/funcnodes/blob/main/docs/content/api/cli.md These are the specific tasks that can be performed on a worker instance after specifying the worker. They range from basic lifecycle management (new, start, stop) to interaction and information retrieval (modules, list, listen, activate, py). ```bash - [new][worker_new] → Creates a new Worker - [start][worker_start] → Runs the existing worker - [stop][worker_stop] → Stops the existing, running worker - [modules][worker_modules] → Runs the `funcnodes module` command in the Worker env - [list][worker_list] → List all existing workers - [listen][worker_listen] → Listens to the output of an existing worker - [activate][worker_activate] → Activates the environment of an existing worker (if present) - [py][worker_py] → Runs the Python instance of the respective worker ``` -------------------------------- ### Manual Project Structure Setup for FuncNodes Module Source: https://github.com/linkdlab/funcnodes/blob/main/docs/content/extending/writing-modules.md Provides the basic shell commands to manually create the directory structure for a new FuncNodes module. ```bash mkdir funcnodes_mymodule cd funcnodes_mymodule mkdir -p src/funcnodes_mymodule touch src/funcnodes_mymodule/__init__.py touch src/funcnodes_mymodule/nodes.py touch pyproject.toml ``` -------------------------------- ### New Worker Creation Options Source: https://github.com/linkdlab/funcnodes/blob/main/docs/content/api/cli.md These options modify the behavior of the 'new worker' command. '--create-only' prevents the worker from starting immediately after creation. '--not-in-venv' uses the current Python interpreter instead of creating a new virtual environment, which can be useful for development. ```bash --create-only By default a newly created worker will automatically start. By setting this flag it will only be created and not started --not-in-venv By default new workers will also create their own virtual environment in there respective path. By setting this flag the worker will be initiated with the current python interpreter (and always use this interpreter even if started from another environment) (--workertype) | Defines the workertype (this feature is under development and should not be used currently) ``` -------------------------------- ### Install FuncNodes Module via CLI Source: https://github.com/linkdlab/funcnodes/blob/main/docs/content/modules/index.md Command-line interface command to install a FuncNodes module. This is an alternative to installing modules through the user interface's 'Manage Libraries' section. Ensure you replace `` with the actual name of the module you wish to install. ```bash funcnodes modules install ``` -------------------------------- ### Library Shelf Mounting and Node Finding (Python) Source: https://github.com/linkdlab/funcnodes/blob/main/docs/content/components/shelf.md Demonstrates how shelves are mounted into a `Library` instance at runtime and how nodes are located using path-aware methods. This includes merging shelves and handling external shelves. ```python from funcnodes.core.lib import Library # Assuming library is an instance of Library # library.add_shelf(shelf_instance) # library.add_external_shelf(external_shelf_instance) # Finding nodes by ID # shelf_paths = library.find_nodeid("unique_node_id") # node = library.get_node_by_id("unique_node_id") ``` -------------------------------- ### Module Loading Flow Diagram Source: https://github.com/linkdlab/funcnodes/blob/main/docs/content/architecture/overview.md Illustrates the process of discovering, loading, and registering modules within the FuncNodes environment. It covers scanning Python environments, importing modules, loading entry points, and populating the node library. ```mermaid flowchart TD subgraph Discovery["Module Discovery"] Venv["Python Environment
(worker's venv)"] Scan["Scan installed packages for
funcnodes.module entry point"] subgraph Load["For each module"] Import["Import module"] Shelf["Load shelf entry point"] Register["Register nodes in Library"] Render["Load render_options"] Plugin["Load react_plugin info"] end Library["Library populated with
shelves and node classes"] end Venv --> Scan Scan --> Import Import --> Shelf Shelf --> Register Register --> Render Render --> Plugin Plugin --> Library ``` -------------------------------- ### Add Package Dependency (JSON) Source: https://github.com/linkdlab/funcnodes/blob/main/docs/content/architecture/message-protocol.md Installs a new package dependency for the worker. You can specify a particular version or `null` to install the latest compatible version. ```json { "type": "cmd", "cmd": "add_package_dependency", "kwargs": { "package": "funcnodes-plotly", "version": null // or specific version } } ``` -------------------------------- ### Module Discovery Configuration and Process Source: https://github.com/linkdlab/funcnodes/blob/main/docs/content/architecture/core-components.md Details the configuration in `pyproject.toml` for discovering funcnodes modules via entry points and the Python code that performs this discovery. It iterates through installed distributions, loads specified modules, and adds their shelves to the library. ```python # Entry point in pyproject.toml: [project.entry-points."funcnodes.module"] module = "funcnodes_numpy" shelf = "funcnodes_numpy:NODE_SHELF" # Discovery process: def discover_modules(): for dist in importlib.metadata.distributions(): eps = dist.entry_points if "funcnodes.module" in eps.groups: for ep in eps["funcnodes.module"]: if ep.name == "shelf": shelf = ep.load() library.add_shelf(shelf) ``` -------------------------------- ### Install pytest-funcnodes Source: https://github.com/linkdlab/funcnodes/blob/main/docs/content/extending/testing-modules.md Install the `pytest-funcnodes` package using pip. This is the primary step to enable advanced testing features for your FuncNodes modules. ```bash pip install pytest-funcnodes ``` -------------------------------- ### Example of Funcnodes Node Triggering Logic (Python) Source: https://github.com/linkdlab/funcnodes/blob/main/README.md Illustrates how a simple 'add' function behaves when wrapped as a Funcnodes Node. It shows that if inputs are set sequentially, the function might be called multiple times. This highlights the event-driven nature of node triggering and the importance of understanding input dependencies. ```python def add(a,b=1): return a + b ``` -------------------------------- ### Create Basic Addition Node (Python) Source: https://context7.com/linkdlab/funcnodes/llms.txt Demonstrates creating a simple addition node using the `NodeDecorator`. This node takes two float inputs and returns their sum as a float output. It includes an example of how to instantiate and run the node programmatically. ```python import funcnodes as fn import asyncio @fn.NodeDecorator(node_id="my_module.add_numbers") def add_numbers(a: float, b: float) -> float: """Add two numbers together.""" return a + b # Usage async def main(): node = add_numbers() node.inputs["a"].value = 10.5 node.inputs["b"].value = 20.3 await node # Wait for execution print(node.outputs["out"].value) # Output: 30.8 asyncio.run(main()) ``` -------------------------------- ### Start FuncNodes Worker Manager (CLI) Source: https://context7.com/linkdlab/funcnodes/llms.txt Starts the FuncNodes WorkerManager, which coordinates communication between the UI and workers via WebSockets. Supports specifying custom host and port for the manager. ```bash # Start with default settings (localhost:9380) funcnodes startworkermanager # Custom host and port funcnodes startworkermanager --host 0.0.0.0 --port 9400 ``` -------------------------------- ### FuncNodes Shelf Discovery via Entry Points (TOML) Source: https://github.com/linkdlab/funcnodes/blob/main/docs/content/components/shelf.md Illustrates how FuncNodes discovers shelves defined in Python packages using the `project.entry-points."funcnodes.module"` section in `pyproject.toml`. ```toml [project.entry-points."funcnodes.module"] module = "funcnodes_files" shelf = "funcnodes_files:NODE_SHELF" react_plugin = "funcnodes_files:REACT_PLUGIN" ``` -------------------------------- ### Instantiating and Using a Custom Node (Python) Source: https://github.com/linkdlab/funcnodes/blob/main/README.md Demonstrates how to create an instance of a custom Funcnodes node and add it to a `NodeSpace`. This is the final step after defining a custom node class, making it available for use within the Funcnodes environment. ```python from funcnodes import NodeSpace ns = NodeSpace() custom_node = MyCustomNode() # Add the node to the node space ns.add_node_instance(custom_node) ``` -------------------------------- ### Configuring `pyproject.toml` for a FuncNodes Module Source: https://github.com/linkdlab/funcnodes/blob/main/docs/content/extending/writing-modules.md Shows a sample `pyproject.toml` file for a FuncNodes module, including build system, project metadata, dependencies, and critical entry points for module discovery. ```toml [build-system] requires = ["hatchling"] build-backend = "hatchling.build" [project] name = "funcnodes-mymodule" version = "0.1.0" description = "My custom FuncNodes module" readme = "README.md" license = "MIT" authors = [ { name = "Your Name", email = "you@example.com" } ] classifiers = [ "Programming Language :: Python :: 3", "License :: OSI Approved :: MIT License", ] dependencies = [ "funcnodes-core>=0.2.0", ] [project.optional-dependencies] dev = [ "pytest", "funcnodes-pytest", ] # CRITICAL: Entry points for FuncNodes discovery [project.entry-points."funcnodes.module"] module = "funcnodes_mymodule" shelf = "funcnodes_mymodule:NODE_SHELF" [tool.hatch.build.targets.wheel] packages = ["src/funcnodes_mymodule"] ``` -------------------------------- ### Nodespace Serialization Example Source: https://github.com/linkdlab/funcnodes/blob/main/docs/content/components/serialization.md Provides an example code snippet for nodespace serialization, which is used for saving the state of the graph in FuncNodes. This involves serializing nodes, edges, and groups into a JSON file. -------------------------------- ### Connecting Nodes in Funcnodes (Python) Source: https://github.com/linkdlab/funcnodes/blob/main/README.md Demonstrates how to establish connections between node inputs and outputs in Funcnodes using Python. It showcases direct connection, shorthand notation, and operator-based connections. Note that by default, inputs accept only one connection, and existing connections are managed with optional replacement. ```python add_node1 = add_node() add_node2 = add_node() add_node1.outputs["out"].connect(add_node2.inputs["a"]) # or short via: add_node1.o["out"].c(add_node2.i["a"]) # or shorter: add_node1.o["out"] > add_node2.i["a"] ``` -------------------------------- ### Complete Example: Custom Measurement Type Serialization Source: https://github.com/linkdlab/funcnodes/blob/main/docs/content/components/serialization.md A comprehensive example demonstrating JSON serialization and deserialization for a custom `Measurement` dataclass. It includes custom encoders and decoders for both JSON and byte formats. ```python import funcnodes_core as fn from funcnodes_core.utils.serialization import ( JSONEncoder, JSONDecoder, ByteEncoder, Encdata, BytesEncdata ) from dataclasses import dataclass @dataclass class Measurement: timestamp: float values: list[float] unit: str # JSON Encoder def measurement_encoder(obj, preview=False): if isinstance(obj, Measurement): data = { "__type__": "Measurement", "timestamp": obj.timestamp, "values": obj.values[:10] if preview else obj.values, "unit": obj.unit, } return Encdata(data=data, handeled=True, done=True) return Encdata(data=obj, handeled=False) JSONEncoder.add_encoder(measurement_encoder, enc_cls=[Measurement]) # JSON Decoder def measurement_decoder(obj): if isinstance(obj, dict) and obj.get("__type__") == "Measurement": return Measurement( timestamp=obj["timestamp"], values=obj["values"], unit=obj["unit"] ), True return obj, False JSONDecoder.add_decoder(measurement_decoder) # Byte Encoder (for efficient binary transfer) def measurement_byte_encoder(obj, preview=False): if isinstance(obj, Measurement): import json data = json.dumps({ "timestamp": obj.timestamp, "values": obj.values, "unit": obj.unit, }).encode("utf-8") return BytesEncdata(data=data, handeled=True, mime="application/json") return BytesEncdata(data=obj, handeled=False) ByteEncoder.add_encoder(measurement_byte_encoder, enc_cls=[Measurement]) ``` -------------------------------- ### Include Built JS in Python Package Source: https://github.com/linkdlab/funcnodes/blob/main/docs/content/extending/react-plugins.md Configuration examples for packaging the built JavaScript files into a Python wheel. Supports both Hatch and Setuptools, ensuring the React plugin directory is correctly included. ```toml # pyproject.toml [tool.hatch.build.targets.wheel] packages = ["src/funcnodes_mymodule"] # Include the react_plugin directory [tool.hatch.build.targets.wheel.force-include] "src/funcnodes_mymodule/react_plugin" = "funcnodes_mymodule/react_plugin" ``` ```python # setup.py or pyproject.toml package_data = { "funcnodes_mymodule": ["react_plugin/*.js", "react_plugin/*.css"] } ``` -------------------------------- ### Manage Funcnodes Worker Libraries Source: https://github.com/linkdlab/funcnodes/blob/main/docs/content/faq/common-issues.md Demonstrates how to install modules within a specific Funcnodes worker's environment using the CLI. After installation, the worker must be restarted for the changes to take effect. ```bash # Install a module inside a worker funcnodes worker --name modules install # Example: Install funcnodes-plotly funcnodes worker --name modules install funcnodes-plotly ``` -------------------------------- ### Connect nodes to build data flow pipelines Source: https://context7.com/linkdlab/funcnodes/llms.txt Illustrates various methods for connecting node outputs to inputs to create data flow pipelines. It shows full connection syntax, short syntax (`.o` and `.c`), and mentions operator syntax (`>`). The example demonstrates how values propagate through connected nodes. ```python import funcnodes as fn import asyncio @fn.NodeDecorator(node_id="example.add") def add(a: float, b: float) -> float: return a + b @fn.NodeDecorator(node_id="example.multiply") def multiply(a: float, b: float) -> float: return a * b async def main(): # Create nodes add_node = add() mult_node = multiply() # Method 1: Full connection syntax add_node.outputs["out"].connect(mult_node.inputs["a"]) # Method 2: Short syntax add_node.o["out"].c(mult_node.i["b"]) # Method 3: Operator syntax # add_node.o["out"] > mult_node.i["a"] # Set initial values add_node.inputs["a"].value = 5 add_node.inputs["b"].value = 3 # Wait for add_node to complete await add_node print(f"Add result: {add_node.outputs['out'].value}") # Output: 8 # mult_node automatically receives the value and triggers await mult_node print(f"Multiply result: {mult_node.outputs['out'].value}") # Output: 64 asyncio.run(main()) ``` -------------------------------- ### Create a class-based node for multiplication Source: https://context7.com/linkdlab/funcnodes/llms.txt Illustrates how to create a custom node by subclassing `fn.Node`. This example defines inputs (`a`, `b`), an output (`result`), and implements the core logic within the `func` method for multiplying two numbers. It also shows how to instantiate and run the node. ```python import funcnodes as fn import asyncio class MultiplyNode(fn.Node): node_id = "my_module.multiply" node_name = "Multiply Numbers" description = "Multiplies two numbers together" # Define inputs a = fn.NodeInput(id="a", type=float, default=1.0) b = fn.NodeInput(id="b", type=float, default=1.0) # Define outputs result = fn.NodeOutput(id="result", type=float) async def func(self, a: float, b: float): self.outputs["result"].value = a * b # Usage async def main(): node = MultiplyNode() node.inputs["a"].value = 7.0 node.inputs["b"].value = 6.0 await node print(node.outputs["result"].value) # Output: 42.0 asyncio.run(main()) ```