Skip to main content

Python SDK for generating WhatsApp Flows using LLMs

Project description

Roovy SDK

A Python SDK for generating WhatsApp Flows using LLMs. Generate valid, schema-compliant WhatsApp Flow JSON from natural language descriptions.

Features

  • 🚀 Simple API - Generate WhatsApp Flows with a single function call
  • Schema Validation - Built-in Pydantic models ensure valid output
  • 🔄 Auto-Retry - Automatic retries with error feedback for better results
  • 📡 Streaming Support - Stream responses for real-time feedback
  • 🔌 Provider Agnostic - Works with OpenAI, Groq, Ollama, or any OpenAI-compatible API
  • 📝 Type Safe - Full type hints and Pydantic models

Installation

pip install roovy-sdk

Quick Start

from roovy_sdk import RoovyClient

# Initialize with your preferred provider
client = RoovyClient(
    api_key="your-api-key",
    base_url="https://api.openai.com/v1",  # or any OpenAI-compatible endpoint
    model="gpt-4o",
)

# Generate a WhatsApp Flow from natural language
flow = client.generate(
    "Create a customer feedback form with name, email, rating (1-5 stars), and comments"
)

# Access the validated flow
print(flow.model_dump_json(indent=2, by_alias=True))

Configuration

Using Environment Variables

import os
from roovy_sdk import RoovyClient

# Set environment variables
os.environ["ROOVY_API_KEY"] = "your-api-key"
os.environ["ROOVY_BASE_URL"] = "https://api.openai.com/v1"
os.environ["ROOVY_MODEL"] = "gpt-4o"

# Client will use environment variables automatically
client = RoovyClient()

Provider Examples

OpenAI:

client = RoovyClient(
    api_key="sk-...",
    base_url="https://api.openai.com/v1",
    model="gpt-4o",
)

Groq:

client = RoovyClient(
    api_key="gsk_...",
    base_url="https://api.groq.com/openai/v1",
    model="llama-3.3-70b-versatile",
)

Ollama (local):

client = RoovyClient(
    api_key="ollama",  # any non-empty string
    base_url="http://localhost:11434/v1",
    model="llama3.2",
)

Advanced Usage

Streaming Generation

def on_chunk(chunk: str):
    print(chunk, end="", flush=True)

flow = client.generate_stream(
    "Create a booking form for a concert",
    on_chunk=on_chunk,
)

Custom Retry Settings

flow = client.generate(
    "Create a survey form",
    max_retries=5,
    temperature=0.3,
)

Custom System Prompt

flow = client.generate(
    "Create a registration form",
    system_prompt="You are a WhatsApp Flows expert...",
)

Direct Schema Access

from roovy_sdk.schema import (
    WhatsAppFlow,
    Screen,
    TextInput,
    Footer,
    validate_flow,
)

# Build flows programmatically
screen = Screen(
    id="WELCOME",
    title="Welcome",
    layout=SingleColumnLayout(
        type="SingleColumnLayout",
        children=[
            TextHeading(type="TextHeading", text="Hello!"),
        ]
    )
)

# Validate any JSON against the schema
result = validate_flow({"version": "7.2", "screens": [...]})
if result["success"]:
    flow = result["data"]

Schema Reference

The SDK includes complete Pydantic models for all WhatsApp Flow components:

Text Components

  • TextHeading - Main headings
  • TextSubheading - Subheadings
  • TextBody - Body text
  • TextCaption - Small captions

Input Components

  • TextInput - Single-line text input
  • TextArea - Multi-line text input
  • Dropdown - Dropdown selector
  • RadioButtonsGroup - Radio button selection
  • ChipsSelector - Multi-select chips
  • CheckboxGroup - Checkbox group
  • OptIn - Opt-in checkbox

Date/Media Components

  • CalendarPicker - Calendar date picker
  • DatePicker - Simple date picker
  • PhotoPicker - Photo upload
  • DocumentPicker - Document upload
  • Image - Display images

Navigation Components

  • Footer - Screen footer with action
  • Button - Action button
  • EmbeddedLink - Inline link

Conditional Components

  • If - Conditional rendering
  • Switch - Switch/case rendering

Container Components

  • Form - Form container
  • SingleColumnLayout - Screen layout

API Reference

RoovyClient

RoovyClient(
    api_key: str | None = None,      # API key (or ROOVY_API_KEY env var)
    base_url: str | None = None,     # Base URL (or ROOVY_BASE_URL env var)
    model: str | None = None,        # Model name (or ROOVY_MODEL env var)
)

client.generate()

client.generate(
    prompt: str,                     # Natural language description
    *,
    max_retries: int = 3,           # Number of retry attempts
    temperature: float = 0.2,        # LLM temperature
    system_prompt: str | None = None, # Custom system prompt
) -> WhatsAppFlow

client.generate_stream()

client.generate_stream(
    prompt: str,                     # Natural language description
    on_chunk: Callable[[str], None] | None = None,  # Chunk callback
    *,
    temperature: float = 0.2,        # LLM temperature
    system_prompt: str | None = None, # Custom system prompt
) -> WhatsAppFlow

validate_flow()

from roovy_sdk import validate_flow

result = validate_flow(flow_dict)
# Returns: {"success": True, "data": WhatsAppFlow} or {"success": False, "error": ValidationError}

License

MIT License - see LICENSE for details.

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

roovy_sdk-0.1.0.tar.gz (12.7 kB view details)

Uploaded Source

Built Distribution

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

roovy_sdk-0.1.0-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

File details

Details for the file roovy_sdk-0.1.0.tar.gz.

File metadata

  • Download URL: roovy_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 12.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.6

File hashes

Hashes for roovy_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 62ccdfd10ee7fbd9933f0ea36e9669c260994a8654d73f8913f72047d4a4eeb5
MD5 ae7b97300ad133c61c2d9cfb8ae34b36
BLAKE2b-256 f20d23d536e65ea47f2914d313cdb65a7f503ff9d0165790979ef727f2fa6fb7

See more details on using hashes here.

File details

Details for the file roovy_sdk-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: roovy_sdk-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.6

File hashes

Hashes for roovy_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 377fabd3bdc358ed1029a98ac741d628395121b4e809ea6200a9372a2ca00617
MD5 cab21e7d11ec64045551519789af0f3a
BLAKE2b-256 7cece03ec9ab4c0472dddff350f34d04c7b9ac24fb193c108a1af5f1cac00bb4

See more details on using hashes here.

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