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.ai
    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.1.1.tar.gz (13.2 kB view details)

Uploaded Source

Built Distribution

workflowai-0.1.1-py3-none-any.whl (21.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: workflowai-0.1.1.tar.gz
  • Upload date:
  • Size: 13.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for workflowai-0.1.1.tar.gz
Algorithm Hash digest
SHA256 0f6e586faf8233acaba4baa42ec48d0dca223038efdf33dafd95de53dacea3f2
MD5 61408e4dbc077b04334c523582d9a415
BLAKE2b-256 b34e7dbe135df14f5f5d644b6b92968c91b4069f4ed2b458092bc979e73bc1e2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: workflowai-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 21.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for workflowai-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cf8814718e72a4f719286f59e4bc48dd47faaaf1bf8ea41e4a23224e743c9496
MD5 29a0d1d0ed10bb7ea215abe333e98164
BLAKE2b-256 c940b528c553e79a5ea6ee5a0444f9ad957a2e81ad2095458329da75ca44d1d6

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