Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically serialize dataclass / pydantic models into param.Parameterized? #809

Open
ahuang11 opened this issue Aug 1, 2023 · 1 comment
Labels
TRIAGE User-submitted issue that hasn't been triaged yet. type-feature Feature request

Comments

@ahuang11
Copy link
Contributor

ahuang11 commented Aug 1, 2023

I was wondering whether we can (or if it's useful to) convert dataclass/pydantic models into param.Parameterized classes?

from dataclasses import dataclass
import param
import panel as pn

@dataclass
class User():
    name: str
    avatar: str

@dataclass
class Message():

    text: str


class UserRow(pn.widgets.CompositeWidget):
    user = param.ClassSelector(class_=User, doc="The user to display.")
    message = param.ClassSelector(class_=Message, doc="The message to display.")

    _composite_type = pn.Row

    def __init__(self, **params):
        super().__init__(**params)
        name = self.user.name
        avatar = self.user.avatar
        self._composite[:] = [
            pn.pane.HTML(avatar),
            pn.Column(
                pn.pane.Markdown(f"**{name}**"),
                pn.pane.Markdown(self.message.text),
            )
        ]


UserRow(user=User(name="Andrew", avatar="A"), message=Message(text="Hello!"))
@ahuang11 ahuang11 added type-feature Feature request TRIAGE User-submitted issue that hasn't been triaged yet. labels Aug 1, 2023
@MarcSkovMadsen
Copy link
Collaborator

MarcSkovMadsen commented Aug 1, 2023

There is already a repository/ Project trying to do this.

I also started working in this in One of my branches of the Project Paithon.

@jbednar jbednar changed the title Automatically serialize dataclass / pydantic models into param.Parametrized? Automatically serialize dataclass / pydantic models into param.Parameterized? Aug 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
TRIAGE User-submitted issue that hasn't been triaged yet. type-feature Feature request
Projects
None yet
Development

No branches or pull requests

2 participants