/yaml2workflow

Manage and create Clarifai workflows with yaml files

Primary LanguagePythonMIT LicenseMIT

yaml2workflow

PyPi version Python 3.7 Github Actions

Clarifai workflows are powerful tools. Building them via the API is a sure way to automate this process, especially if you have many nodes and branches.

Taking inspiration from Kubernetes Helm Charts and AWS Cloud Formation templates, yaml2workflow is designed to make automating the creation and managing the definition of workflows easier and more transparent.

🙌 Define Workflows as YAML files

Much clearer and more human-readable definitions without distractors. Also, by storing the workflow definitions as a file, you can now use version control for your future automations! Winning.

# A single node workflow
workflow:
  id: test-wf-1
  nodes:
    - id: detector
      model:
          model_id: face-detection
          model_version_id: 45fb9a671625463fa646c3523a3087d5

🙌 Export Workflows as YAML files

[New!] Export your workflows into YAML files as well. Simply pass in the workflow object from a GetWorkflow response. See export_example.py for how to do that.

from yaml2workflow.exporter.workflow import Exporter

with Exporter(response.workflow) as e:
  e.parse()
  e.export("export_example.yml")

🚀 Installation

Simply enter

pip install yaml2workflow

💪 Usage

  1. Create a YAML file to define your workflow. Gather the model IDs and model version IDs from Clarifai. See parse_example.yml for a full, filled in template.
  2. Import the library and use it directly in your code as follows:
from yaml2workflow.parser.workflow import parse

workflows = parse('parse_example.yml', stub=stub, metadata=metadata)

post_workflows_response = stub.PostWorkflows(
    service_pb2.PostWorkflowsRequest(
        workflows=workflows
    ),
    metadata=metadata
)

See parse_example.py for the full example.

🎉 Done! You've now unlocked more human-readble and more maintable workflows.