Skip to content

Multiple Functions & Groups

Serve multiple functions with an auto-generated index page, optionally organized into collapsible groups.

Multiple Functions

Pass a list of functions to create an index page:

from func_to_web import run

def calculate_bmi(weight_kg: float, height_m: float):
    """Calculate Body Mass Index"""
    return f"BMI: {weight_kg / (height_m ** 2):.2f}"

def celsius_to_fahrenheit(celsius: float):
    """Convert Celsius to Fahrenheit"""
    return f"{celsius}°C = {(celsius * 9/5) + 32}°F"

def reverse_text(text: str):
    """Reverse a string"""
    return text[::-1]

run([calculate_bmi, celsius_to_fahrenheit, reverse_text])

Multiple Tools

Grouped Functions

Pass a dictionary to organize functions into collapsible groups:

from func_to_web import run

def add(a: int, b: int):
    return a + b

def multiply(a: int, b: int):
    return a * b

def upper(text: str):
    return text.upper()

def lower(text: str):
    return text.lower()

run({
    'Math': [add, multiply],
    'Text': [upper, lower]
})

Groups display as accordion cards - only one open at a time.

Grouped Functions

Next Steps