No project description provided
Project description
Nodeflow
Nodeflow if a framework to make pipelines from nodes.
Status
Usage
Installing
Requires python version 3.10 or later
pip3 install nodeflow
Import it to your code using:
import nodeflow
Types
In Nodeflow, everything is a subclass of the Node class.
Dev note: This is an old documentation. Newest versions of Nodeflow contain adapters from any2any types.
Variable
Each node encapsulates information for a specific type and functions as a container. The code snippet below is taken from the built-in types:
from nodeflow import Variable
class Integer(Variable):
def __init__(self, value: int):
super().__init__(value)
# optional
def __add__(self, other: 'Integer') -> 'Integer':
return Integer(self.value + other.value)
# optional
def __mul__(self, other: 'Integer') -> 'Integer':
return Integer(self.value * other.value)
Function
A Function node accepts several Variable nodes to perform computations and must return exactly one Variable.
You can define your own function in the following manner:
from nodeflow import Function
class Sum(Function):
def compute(self, a: Integer, b: Integer) -> Integer:
return a + b
However, in practical applications, we recommend using a converter to transform a Python function into a NodeFlow function:
from nodeflow import func2node
def sum_of_integers(a: Integer, b: Integer) -> Integer:
return a + b
Sum = func2node(sum_of_integers)
It is essential to include all type hints since the NodeFlow framework has the capability to derive implicit adapters.
Adapter
This is a subclass of Function. The computations primarily involve converting the types of Variable nodes.
Refer to the examples for clarification.
Dispenser
How can we define our pipeline? If the function takes a single parameter, you can follow this pattern:
my_variable >> my_function
If the function requires multiple values, utilize an instance of the Dispenser:
from nodeflow import Dispenser, func2node
def increment(a: Integer) -> Integer:
return Integer(a.value + 1)
def sum_of_integers(a: Integer, b: Integer) -> Integer:
return a + b
result = Dispenser(
a = Integer(5) >> func2node(increment),
b = Integer(10),
) >> func2node(sum_of_integers)
# results.value == 16
Converter
A few words about deriving implicit adapters. The core of NodeFlow provides a solution for identifying the shortest
path of explicit adapters that can convert one type to another when possible.
The conversion pipeline may sometimes lead to information loss, but the following priority list can guide the process:
- Shortest pipeline without losing information
- Shortest pipeline with information loss
- Long pipeline without losing information better than short pipeline with information loss
Contributing
See CONTRIBUTING.md file.
Licence
Special thanks
Thank you for your interest in the project description!
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nodeflow-0.1.0.tar.gz.
File metadata
- Download URL: nodeflow-0.1.0.tar.gz
- Upload date:
- Size: 8.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.12.7 Linux/6.5.0-1025-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f70389a1f4071c2dab91eae94b3e28a41688526966ed6a35beaff064feaba100
|
|
| MD5 |
8812590311dc339602bfe1f7ee145831
|
|
| BLAKE2b-256 |
49a9e3adbe0383cfd5d7f334bccf380261f0e0e1c465f10406b5760754cd0824
|
File details
Details for the file nodeflow-0.1.0-py3-none-any.whl.
File metadata
- Download URL: nodeflow-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.12.7 Linux/6.5.0-1025-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
05b4a4182e6996e0f00e2858cf1efcf520e942b4d0a6c9bd909a7de28f3453b9
|
|
| MD5 |
c884869218e73a81bf4c408e8372dcfc
|
|
| BLAKE2b-256 |
a7805ae63bc8b478a8185f70c4ec41718bf027e88dda04c047e1bb6dc6696266
|