Skip to main content

Python SDK for WorkflowAI

Project description

header

Python SDK for WorkflowAI

PyPI version License: Apache 2.0 Python versions

Official SDK from WorkflowAI for Python.

This SDK is designed for Python teams who prefer code-first development. It provides greater control through direct code integration while still leveraging the full power of the WorkflowAI platform, complementing the web-app experience.

Key Features

  • Model-agnostic: Works with all major AI models including OpenAI, Anthropic, Claude, Google/Gemini, Mistral, Deepseek, with a unified interface that makes switching between providers seamless. View all supported models.

  • Open-source and flexible deployment: WorkflowAI is fully open-source with flexible deployment options. Run it self-hosted on your own infrastructure for maximum data control, or use the managed WorkflowAI Cloud service for hassle-free updates and automatic scaling.

  • Observability integrated: Built-in monitoring and logging capabilities that provide insights into your AI workflows, making debugging and optimization straightforward. Learn more about observability features.

  • Cost tracking: Automatically calculates and tracks the cost of each AI model run, providing transparency and helping you manage your AI budget effectively. Learn more about cost tracking.

  • Type-safe: Leverages Python's type system to catch errors at development time rather than runtime, ensuring more reliable AI applications.

  • Structured output: Uses Pydantic models to validate and structure AI responses. WorkflowAI ensures your AI responses always match your defined structure, simplifying integrations, reducing parsing errors, and making your data reliable and ready for use. Learn more about structured input and output.

  • Streaming supported: Enables real-time streaming of AI responses for low latency applications, with immediate validation of partial outputs. Learn more about streaming capabilities.

  • Provider fallback: Automatically switches to alternative AI providers when the primary provider fails, ensuring high availability and reliability for your AI applications. This feature allows you to define fallback strategies that maintain service continuity even during provider outages or rate limiting.

  • Built-in tools: Comes with powerful built-in tools like web search and web browsing capabilities, allowing your agents to access real-time information from the internet. These tools enable your AI applications to retrieve up-to-date data, research topics, and interact with web content without requiring complex integrations. Learn more about built-in tools.

  • Custom tools support: Easily extend your agents' capabilities by creating custom tools tailored to your specific needs. Whether you need to query internal databases, call external APIs, or perform specialized calculations, WorkflowAI's tool framework makes it simple to augment your AI with domain-specific functionality. Learn more about custom tools.

  • Integrated with WorkflowAI: The SDK seamlessly syncs with the WorkflowAI web application, giving you access to a powerful playground where you can edit prompts and compare models side-by-side. This hybrid approach combines the flexibility of code-first development with the visual tools needed for effective prompt engineering and model evaluation.

  • Multimodality support: Build agents that can handle multiple modalities, such as images, PDFs, documents, and audio. Learn more about multimodal capabilities.

  • Caching support: To save money and improve latency, WorkflowAI supports caching. When enabled, identical requests return cached results instead of making new API calls to AI providers. Learn more about caching capabilities.

Get Started

workflowai requires Python 3.9 or higher.

pip install workflowai

API Key

To get started quickly, get an API key from WorkflowAI Cloud. For maximum control over your data, you can also use your self-hosted instance, though this requires additional setup time.

Then, set the WORKFLOWAI_API_KEY environment variable:

export WORKFLOWAI_API_KEY="your-api-key"

First Agent

Here's a simple example of a WorkflowAI agent that extracts structured flight information from email content:

import asyncio
from datetime import datetime
from enum import Enum

from pydantic import BaseModel, Field

import workflowai
from workflowai import Model

# Input class
class EmailInput(BaseModel):
    email_content: str

# Output class
class FlightInfo(BaseModel):
    # Enum for standardizing flight status values
    class Status(str, Enum):
        """Possible statuses for a flight booking."""
        CONFIRMED = "Confirmed"
        PENDING = "Pending"
        CANCELLED = "Cancelled"
        DELAYED = "Delayed"
        COMPLETED = "Completed"

    passenger: str
    airline: str
    flight_number: str
    from_airport: str = Field(description="Three-letter IATA airport code for departure")
    to_airport: str = Field(description="Three-letter IATA airport code for arrival")
    departure: datetime
    arrival: datetime
    status: Status

# Agent definition
@workflowai.agent(
    id="flight-info-extractor",
    model=Model.GEMINI_2_0_FLASH_LATEST,
)
async def extract_flight_info(email_input: EmailInput) -> FlightInfo:
    # Agent prompt
    """
    Extract flight information from an email containing booking details.
    """
    ...


async def main():
    email = """
    Dear Jane Smith,

    Your flight booking has been confirmed. Here are your flight details:

    Flight: UA789
    From: SFO
    To: JFK
    Departure: 2024-03-25 9:00 AM
    Arrival: 2024-03-25 5:15 PM
    Booking Reference: XYZ789

    Total Journey Time: 8 hours 15 minutes
    Status: Confirmed

    Thank you for choosing United Airlines!
    """
    run = await extract_flight_info.run(EmailInput(email_content=email))
    print(run)


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


# Output:
# ==================================================
# {
#   "passenger": "Jane Smith",
#   "airline": "United Airlines",
#   "flight_number": "UA789",
#   "from_airport": "SFO",
#   "to_airport": "JFK",
#   "departure": "2024-03-25T09:00:00",
#   "arrival": "2024-03-25T17:15:00",
#   "status": "Confirmed"
# }
# ==================================================
# Cost: $ 0.00009
# Latency: 1.18s
# URL: https://workflowai.com/_/agents/flight-info-extractor/runs/0195ee02-bdc3-72b6-0e0b-671f0b22b3dc

Ready to run! This example works straight out of the box - no tweaking needed.

Agents built with workflowai SDK can be run in the WorkflowAI web application too.

WorkflowAI Playground

And the runs executed via the SDK are synced with the web application.

WorkflowAI Runs

Documentation

Complete documentation is available at docs.workflowai.com/python-sdk.

Example

Examples are available in the examples directory.

Workflows

For advanced workflow patterns and examples, please refer to the Workflows README for more details.

Contributing

See the CONTRIBUTING.md file for more details. Thank you!

Acknowledgments

Thanks to ell for the inspiration! ✨

Project details


Release history Release notifications | RSS feed

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

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

workflowai-0.6.6-py3-none-any.whl (52.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: workflowai-0.6.6.tar.gz
  • Upload date:
  • Size: 42.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for workflowai-0.6.6.tar.gz
Algorithm Hash digest
SHA256 9524b6cbf27d764fb9431ff82527a8a57e35be241453439f9766c2955cff3f43
MD5 e4cf3b73c107591459af75b345193021
BLAKE2b-256 6cf79294eeb3f9dde049dc1c70350d15c1574708dbfc0232c7ee188bd9af3f6b

See more details on using hashes here.

Provenance

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

Publisher: publish.yml on WorkflowAI/python-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: workflowai-0.6.6-py3-none-any.whl
  • Upload date:
  • Size: 52.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for workflowai-0.6.6-py3-none-any.whl
Algorithm Hash digest
SHA256 b0ac959e5236275b2559e4f0956ad9b65f1e824244418af0d9ceeb8e240d9cb7
MD5 ae098e9d2812005976241a3d7525ac02
BLAKE2b-256 440cf2692a00918bcea070038272a97a9667a0c336c16385630bc947c04bf626

See more details on using hashes here.

Provenance

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

Publisher: publish.yml on WorkflowAI/python-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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