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.2.2.tar.gz (16.5 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.2.2-py3-none-any.whl (18.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: roovy_sdk-0.2.2.tar.gz
  • Upload date:
  • Size: 16.5 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.2.2.tar.gz
Algorithm Hash digest
SHA256 3d20bcec5f4cca70ea271b3385405f7e2288750b7c1c147d057853a085aaa58e
MD5 2ce68bddd7dc3d6fe2aa2c984e61f883
BLAKE2b-256 b767442d66d19e6414052b2a796e4c18f02d01b5ea0a1c38aec2ca15eb147775

See more details on using hashes here.

File details

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

File metadata

  • Download URL: roovy_sdk-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 18.8 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.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 524c1ceb61098f284a77b75a6bc28fc13d5529fe606950d2c43940187de3b3db
MD5 a69da1af5611ce6b7ec097fde5dc8b93
BLAKE2b-256 b90c10e99492887531596d408c9eddea6ab07a8dc1a6bf86fec992e80b534058

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