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.4.0.tar.gz (12.7 kB view details)

Uploaded Source

Built Distribution

workflowai-0.4.0-py3-none-any.whl (20.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for workflowai-0.4.0.tar.gz
Algorithm Hash digest
SHA256 3879b151ccaf05016c1f3cabcc0a72537965ab4956144aae7ef9f8883342003b
MD5 38de939f710ca2f1516871e6097eb09a
BLAKE2b-256 b1e4246af7de6cae7c4696a2aea7d2c76d62fe9b81442ce9665018da3c4766ef

See more details on using hashes here.

Provenance

The following attestation bundles were made for workflowai-0.4.0.tar.gz:

Publisher: publish.yml on workflowai/workflowai-py

Attestations:

File details

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

File metadata

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

File hashes

Hashes for workflowai-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9d067e108721feca630c577a792f19ac68220ee4438c86cddf965ec337aa4b33
MD5 1e150d5d63ee5481c34b2fbd15f9fb52
BLAKE2b-256 54e0e66eb7a8250e52fdb779bfa99a56b3370e4363b6787c1eadf679aa3a41a4

See more details on using hashes here.

Provenance

The following attestation bundles were made for workflowai-0.4.0-py3-none-any.whl:

Publisher: publish.yml on workflowai/workflowai-py

Attestations:

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