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

Support pydantic types #98

Open
tlambert03 opened this issue Jan 14, 2021 · 6 comments
Open

Support pydantic types #98

tlambert03 opened this issue Jan 14, 2021 · 6 comments
Labels
enhancement New feature or request

Comments

@tlambert03
Copy link
Member

As @sofroniewn suggested, pydantic's constrained types make for a natural way to express things like ranges and widget parameters as type annotations. We should detect and support pydantic types

@tlambert03 tlambert03 added the enhancement New feature or request label Jan 14, 2021
@aeisenbarth
Copy link
Contributor

Currently I am building my user interface using the direct widget API and noticed I should avoid repetition by keeping widget constraints (type, min/max) in a central place, my data model which is a Pydantic class and has all these constraints. As a Pydantic class (from which I can generate documentation) it also can hold widget texts (Pydantic title) and tooltips (Pydantic description). Basically I ended up with rather repetitive code that feeds each Pydantic field property to an argument of the widget constructor.

It would be nice to generate a magicgui either from a pydantic class (like magic-class from basic dataclasses), or to have something similar to widgets.create_widget() with a Pydantic field as single required argument.

@tlambert03
Copy link
Member Author

tlambert03 commented Nov 13, 2021

thanks @aeisenbarth ... I have a local branch where I started to implement this. will try to get back on it soon

@imagejan
Copy link

Seeing the discussions in #474 and #475, is the plan still to have first-class support for Pydantic classes?
Or should I rather look into using @dataclass or @guiclass?

@tlambert03
Copy link
Member Author

tlambert03 commented Feb 20, 2024

it's basically possible already with the logic underlying guiclass, but not everything is public yet.
Can you read through this topic on imagesc and let me know what your specific desired use case would be?
https://forum.image.sc/t/building-a-napari-widget-from-a-pydantic-model/90257/5

@imagesc-bot
Copy link

This issue has been mentioned on Image.sc Forum. There might be relevant details there:

https://forum.image.sc/t/using-magicgui-to-create-pydantic-class-instances/92520/1

@imagejan
Copy link

Can you read through this topic on imagesc and let me know what your specific desired use case would be?
forum.image.sc/t/building-a-napari-widget-from-a-pydantic-model/90257/5

Thanks @tlambert03, that's a very useful forum post!
I opened a new topic (Using magicgui to create pydantic class instances) to describe my intended use case and post a few more questions 🙂.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants