Skip to main content

Python SDK for generating WhatsApp Flows and Message Templates 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.3.0.tar.gz (21.8 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.3.0-py3-none-any.whl (25.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: roovy_sdk-0.3.0.tar.gz
  • Upload date:
  • Size: 21.8 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.3.0.tar.gz
Algorithm Hash digest
SHA256 5086170d3692318eeb996ef4904199927e9d23b9fc52bbd5cdd787b4711bdb16
MD5 8af1e0c28de666609034b2a2ddce3b4f
BLAKE2b-256 6e9691f317989854b7f8d10cbe1f88629588e496882dcb842e95cd4163e13675

See more details on using hashes here.

File details

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

File metadata

  • Download URL: roovy_sdk-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 25.4 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.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 da0fa6fadcf99a27c2c90ba455e3377b63171269a93234b1fdc56132aafda854
MD5 8aba3afe8cf522518e5ab2250c9c2250
BLAKE2b-256 19cb24d76939eac491250046929ad72bea2a85a9808ef3fa2d18e2c69665ab02

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