carefree-workflow


Namecarefree-workflow JSON
Version 0.1.0 PyPI version JSON
download
home_page
SummaryBuild arbitray workflows with Python!
upload_time2023-12-28 09:44:38
maintainer
docs_urlNone
authorcarefree0910
requires_python
license
keywords python workflow
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # carefree-workflow

`carefree-workflow` is a lightweight library for building arbitray workflows with Python.


## Highlights

- **Async**: `async` is by design.
- **Parallel**: nodes can be executed in parallel.
- **Powerful**: complex locks / logics / dependencies can be handled.
  - You can even perform a loop with loop backs in the workflow!
- **Servable**: all nodes, as well as the workflow itself, can be automatically turned into RESTful APIs.
- **Extensible**: you can easily extend the library with your own nodes.
- **Serializable**: the workflow can be serialized into / deserialized from a single JSON file.
- **Human Readable**: the workflow JSON file is human readable and easy to understand.
- **Lightweight**: the library is lightweight (core implementation is ~500 lines of code in a single file `core.py`) and easy to use.


## Installation

`carefree-workflow` requires Python 3.8 or higher.

```bash
pip install carefree-workflow
```

or

```bash
git clone https://github.com/carefree0910/carefree-workflow.git
cd carefree-workflow
pip install -e .
```


## Usages

### CLI

`carefree-workflow` is installed with a **C**ommand **L**ine **I**nterface (CLI) tool called `cflow`, which can help you execute / render workflows easily:

> Workflow JSON examples can be found in [`examples/workflows`](https://github.com/carefree0910/carefree-workflow/tree/main/examples/workflows).

```bash
cflow execute -f <workflow_json_file>
```

or

```bash
cflow render -f <workflow_json_file>
```

Detailed information can be found by:

```bash
cflow --help
```

### Code

Since `carefree-workflow` is extensible, you can easily extend the library with your own nodes:

```python
import asyncio

from cflow import *

@Node.register("hello")
class HelloNode(Node):
    async def execute(self):
        name = self.data["name"]
        return {"name": name, "greeting": f"Hello, {name}!"}

async def main():
    flow = (
        Flow()
        .push(HelloNode("A", dict(name="foo")))
        .push(HelloNode("B", dict(name="bar")))
        .push(
            EchoNode(
                "Echo",
                dict(messages=[None, None, "Hello, World!"]),
                injections=[
                    Injection("A", "name", "messages.0"),
                    Injection("B", "greeting", "messages.1"),
                ],
            )
        )
    )
    await flow.execute("Echo")

if __name__ == "__main__":
    asyncio.run(main())
```

Running the above codes will yield something like:

```text
[17:30:27] foo
           Hello, bar!
           Hello, World!
```

> More code snippets can be found in [`examples`](https://github.com/carefree0910/carefree-workflow/tree/main/examples).


## Serving

`carefree-workflow` is designed to be servable, here are some rules:

- Only nodes with `get_schema` implemented can be automatically served.
  - See [`cflow/nodes/cv.py`](https://github.com/carefree0910/carefree-workflow/tree/main/cflow/nodes/cv.py) for some examples.
- Complex results (e.g. `PIL.Image`) can be handled if `get_api_response` is implemented.
  - See our [template](https://github.com/carefree0910/carefree-workflow/tree/main/cflow/nodes/templates/complex.py) if you are interested!
- The registered name will be turned into the API endpoint, with the dots (`.`) being replaced by slashes (`/`).
  - e.g. if the node is registered with `Node.register("foo.bar")`, the corresponding API endpoint will be `/foo/bar`.

You can use our CLI to launch a server under default settings easily:

```bash
cflow serve
```

More options can be found by `cflow serve --help`.


## Examples

- Code snippets can be found in [`examples`](https://github.com/carefree0910/carefree-workflow/tree/main/examples).
- Custom node templates can be found in [`cflow/nodes/templates`](https://github.com/carefree0910/carefree-workflow/tree/main/cflow/nodes/templates).
  - And some pre-implemented node examples can be found in [`cflow/nodes/cv.py`](https://github.com/carefree0910/carefree-workflow/tree/main/cflow/nodes/cv.py).
- Workflow JSON files can be found in [`examples/workflows`](https://github.com/carefree0910/carefree-workflow/tree/main/examples/workflows).
  - These JSON files can be executed by `cflow execute -f <workflow_json_file>`.
  - More execution options can be found by `cflow execute --help`.


## License

`carefree-workflow` is MIT licensed, as found in the [`LICENSE`](https://github.com/carefree0910/carefree-workflow/blob/main/LICENSE) file.

---

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "carefree-workflow",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "python workflow",
    "author": "carefree0910",
    "author_email": "syameimaru.saki@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/96/dc/61bb8f3bc2dec4fc54f34dffd5c87619b1cbcc8648b87cb5c1c11ea7fbd6/carefree-workflow-0.1.0.tar.gz",
    "platform": null,
    "description": "# carefree-workflow\r\n\r\n`carefree-workflow` is a lightweight library for building arbitray workflows with Python.\r\n\r\n\r\n## Highlights\r\n\r\n- **Async**: `async` is by design.\r\n- **Parallel**: nodes can be executed in parallel.\r\n- **Powerful**: complex locks / logics / dependencies can be handled.\r\n  - You can even perform a loop with loop backs in the workflow!\r\n- **Servable**: all nodes, as well as the workflow itself, can be automatically turned into RESTful APIs.\r\n- **Extensible**: you can easily extend the library with your own nodes.\r\n- **Serializable**: the workflow can be serialized into / deserialized from a single JSON file.\r\n- **Human Readable**: the workflow JSON file is human readable and easy to understand.\r\n- **Lightweight**: the library is lightweight (core implementation is ~500 lines of code in a single file `core.py`) and easy to use.\r\n\r\n\r\n## Installation\r\n\r\n`carefree-workflow` requires Python 3.8 or higher.\r\n\r\n```bash\r\npip install carefree-workflow\r\n```\r\n\r\nor\r\n\r\n```bash\r\ngit clone https://github.com/carefree0910/carefree-workflow.git\r\ncd carefree-workflow\r\npip install -e .\r\n```\r\n\r\n\r\n## Usages\r\n\r\n### CLI\r\n\r\n`carefree-workflow` is installed with a **C**ommand **L**ine **I**nterface (CLI) tool called `cflow`, which can help you execute / render workflows easily:\r\n\r\n> Workflow JSON examples can be found in [`examples/workflows`](https://github.com/carefree0910/carefree-workflow/tree/main/examples/workflows).\r\n\r\n```bash\r\ncflow execute -f <workflow_json_file>\r\n```\r\n\r\nor\r\n\r\n```bash\r\ncflow render -f <workflow_json_file>\r\n```\r\n\r\nDetailed information can be found by:\r\n\r\n```bash\r\ncflow --help\r\n```\r\n\r\n### Code\r\n\r\nSince `carefree-workflow` is extensible, you can easily extend the library with your own nodes:\r\n\r\n```python\r\nimport asyncio\r\n\r\nfrom cflow import *\r\n\r\n@Node.register(\"hello\")\r\nclass HelloNode(Node):\r\n    async def execute(self):\r\n        name = self.data[\"name\"]\r\n        return {\"name\": name, \"greeting\": f\"Hello, {name}!\"}\r\n\r\nasync def main():\r\n    flow = (\r\n        Flow()\r\n        .push(HelloNode(\"A\", dict(name=\"foo\")))\r\n        .push(HelloNode(\"B\", dict(name=\"bar\")))\r\n        .push(\r\n            EchoNode(\r\n                \"Echo\",\r\n                dict(messages=[None, None, \"Hello, World!\"]),\r\n                injections=[\r\n                    Injection(\"A\", \"name\", \"messages.0\"),\r\n                    Injection(\"B\", \"greeting\", \"messages.1\"),\r\n                ],\r\n            )\r\n        )\r\n    )\r\n    await flow.execute(\"Echo\")\r\n\r\nif __name__ == \"__main__\":\r\n    asyncio.run(main())\r\n```\r\n\r\nRunning the above codes will yield something like:\r\n\r\n```text\r\n[17:30:27] foo\r\n           Hello, bar!\r\n           Hello, World!\r\n```\r\n\r\n> More code snippets can be found in [`examples`](https://github.com/carefree0910/carefree-workflow/tree/main/examples).\r\n\r\n\r\n## Serving\r\n\r\n`carefree-workflow` is designed to be servable, here are some rules:\r\n\r\n- Only nodes with `get_schema` implemented can be automatically served.\r\n  - See [`cflow/nodes/cv.py`](https://github.com/carefree0910/carefree-workflow/tree/main/cflow/nodes/cv.py) for some examples.\r\n- Complex results (e.g. `PIL.Image`) can be handled if `get_api_response` is implemented.\r\n  - See our [template](https://github.com/carefree0910/carefree-workflow/tree/main/cflow/nodes/templates/complex.py) if you are interested!\r\n- The registered name will be turned into the API endpoint, with the dots (`.`) being replaced by slashes (`/`).\r\n  - e.g. if the node is registered with `Node.register(\"foo.bar\")`, the corresponding API endpoint will be `/foo/bar`.\r\n\r\nYou can use our CLI to launch a server under default settings easily:\r\n\r\n```bash\r\ncflow serve\r\n```\r\n\r\nMore options can be found by `cflow serve --help`.\r\n\r\n\r\n## Examples\r\n\r\n- Code snippets can be found in [`examples`](https://github.com/carefree0910/carefree-workflow/tree/main/examples).\r\n- Custom node templates can be found in [`cflow/nodes/templates`](https://github.com/carefree0910/carefree-workflow/tree/main/cflow/nodes/templates).\r\n  - And some pre-implemented node examples can be found in [`cflow/nodes/cv.py`](https://github.com/carefree0910/carefree-workflow/tree/main/cflow/nodes/cv.py).\r\n- Workflow JSON files can be found in [`examples/workflows`](https://github.com/carefree0910/carefree-workflow/tree/main/examples/workflows).\r\n  - These JSON files can be executed by `cflow execute -f <workflow_json_file>`.\r\n  - More execution options can be found by `cflow execute --help`.\r\n\r\n\r\n## License\r\n\r\n`carefree-workflow` is MIT licensed, as found in the [`LICENSE`](https://github.com/carefree0910/carefree-workflow/blob/main/LICENSE) file.\r\n\r\n---\r\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Build arbitray workflows with Python!",
    "version": "0.1.0",
    "project_urls": null,
    "split_keywords": [
        "python",
        "workflow"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "96dc61bb8f3bc2dec4fc54f34dffd5c87619b1cbcc8648b87cb5c1c11ea7fbd6",
                "md5": "220acaebad582a3bf55575100138a44f",
                "sha256": "709c26b2812c4ff937ac97dd16a05446407f3daa988c496284f78cd6a71d0417"
            },
            "downloads": -1,
            "filename": "carefree-workflow-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "220acaebad582a3bf55575100138a44f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 20639,
            "upload_time": "2023-12-28T09:44:38",
            "upload_time_iso_8601": "2023-12-28T09:44:38.431623Z",
            "url": "https://files.pythonhosted.org/packages/96/dc/61bb8f3bc2dec4fc54f34dffd5c87619b1cbcc8648b87cb5c1c11ea7fbd6/carefree-workflow-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-12-28 09:44:38",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "carefree-workflow"
}
        
Elapsed time: 3.13136s