Skip to main content

No project description provided

Project description

WorkflowAI Python

A library to use WorkflowAI with Python

Installation

workflowai requires a python >= 3.9.

pip install workflowai

Usage

Usage examples are available in the examples directory.

Set up the workflowai client

import workflowai

wai = workflowai.start(
    url=..., # defaults to WORKFLOWAI_API_URL env var or https://api.workflowai.com
    api_key=..., # defaults to WORKFLOWAI_API_KEY env var
)

Define a task

We use pydantic for type definitions.

from pydantic import BaseModel, Field

from workflowai import Task, TaskVersionReference

class CityToCapitalTaskInput(BaseModel):
    city: str


class CityToCapitalTaskOutput(BaseModel):
    capital: str

class CityToCapitalTask(Task[CityToCapitalTaskInput, CityToCapitalTaskOutput]):
    id: str = "citytocapital"
    schema_id: int = 1
    input_class: type[CityToCapitalTaskInput] = CityToCapitalTaskInput
    output_class: type[CityToCapitalTaskOutput] = CityToCapitalTaskOutput

    # The default version that should be used when running the task
    version: TaskVersionReference = TaskVersionReference(
        iteration=4,
    )

Run a task

task = CityToCapitalTask()
task_input = CityToCapitalTaskInput(city=city)
task_run = await wai.run(task, task_input)

print(task_run.task_output)

It is also possible to stream a task output

task = CityToCapitalTask()
task_input = CityToCapitalTaskInput(city=city)
iterator = await wai.run(task, task_input, stream=True)
async for chunk in iterator:
    print(chunk) # chunk is a partial (non validated) CityToCapitalTaskOutput

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

workflowai-0.2.2.tar.gz (15.8 kB view details)

Uploaded Source

Built Distribution

workflowai-0.2.2-py3-none-any.whl (24.3 kB view details)

Uploaded Python 3

File details

Details for the file workflowai-0.2.2.tar.gz.

File metadata

  • Download URL: workflowai-0.2.2.tar.gz
  • Upload date:
  • Size: 15.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for workflowai-0.2.2.tar.gz
Algorithm Hash digest
SHA256 03d02019b1246ce2fc8add8bdbec3432b9621629c2f143df883b41c7b745c2c2
MD5 f85823f0294ddd68fb1ce0a466dff33b
BLAKE2b-256 033c297082be5eeccb133b68d01f8d8cc4456a54d7d1c4a53921c59e3ba95beb

See more details on using hashes here.

File details

Details for the file workflowai-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: workflowai-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 24.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for workflowai-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b3e00c4bec9110fa6e68bec935371964996ce86080a86eee5a33e2c9a1c57a64
MD5 d8e215a5849fd993633a23c0398d7301
BLAKE2b-256 e947dce9a2935e6fe329726e5d680e5b2277b230a57678d702fa6328afb81900

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page