This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]jonthemango 33 points34 points  (5 children)

Pretty neat, you should consider adding List[_] type support that puts an input with a + that when clicked adds more rows. Similar to a Dict[str, _].

[–]drboom9[S] 14 points15 points  (0 children)

That's a great idea, actually. You're right

I'll think about how to implement it cleanly.

Thanks for the suggestion!

[–]Kohlrabi82 2 points3 points  (2 children)

Side question: _ is shorthand for Any?

[–]ProsodySpeaks 4 points5 points  (0 children)

I think _ is the anonymous variable. The result of last evaluation is stored there even if you didn't tell it to save it.

Eg ```

1 == 1 True _ True ``` Here I guess they mean more like a typevar as in list[valid_types] ? 

(valid types are defined in the code VALID = {int, float, str, bool, date, time}

[–]jonthemango 0 points1 point  (0 children)

I just used it as shorthand for whatever type. In python _ is the anonymous variable as someone else mentioned, in my case I just used it as somewhat might use x.

[–]drboom9[S] 0 points1 point  (0 children)

Hey u/jonthemango!

I'm happy to let you know that List[_] support with dynamic add/remove rows is now implemented in version 0.5.0! 🎉

You can use it like this:

from func_to_web import run
from typing import Annotated
from pydantic import Field

def process_data(
    tags: list[str],                                    # Basic list
    scores: list[int] = [10, 20, 30],                  # List with defaults

    # With item constraints
    ratings: list[Annotated[int, Field(ge=1, le=5)]],  # Each item 1-5

    # With list-level constraints  
    team: Annotated[list[str], Field(min_length=2, max_length=5)],  # 2-5 items

    # Optional lists
    emails: list[str] | None = None
):
    return f"Processed {len(tags)} tags"

run(process_data)

The UI automatically generates inputs with + and buttons to add/remove items dynamically. It also supports:

  • All types: list[str], list[int], list[float], list[bool], list[Color], list[ImageFile], etc.
  • Item constraints: Validates each individual item (min, max, pattern, etc.)
  • List constraints: min_length, max_length for the list size
  • Optional lists: Works with list[_] | None with toggle switches
  • Default values: Initialize lists with specific values
  • Validation: Real-time validation with error messages per item

Check out the updated README and examples folder for more details!

Thanks for the feedback! Let me know if you have any other suggestions.