-
Notifications
You must be signed in to change notification settings - Fork 130
Python SDK: Allow implicit merge-fragments/signals events and decorator for iterator responses #809
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
base: develop
Are you sure you want to change the base?
Python SDK: Allow implicit merge-fragments/signals events and decorator for iterator responses #809
Conversation
Any update on this, @gazpachoking ? |
b3a68f0
to
9592ee9
Compare
Still thinking on this. Updated it with some of the changes that have happened in the mean time. I guess there are 2 main bits to this that I'd welcome other people's opinions on:
These two pieces could be implemented separately. The second one could be made default for all frameworks without having to use any sort of decorator. Is that too much magic? The first one would use a decorator specific to each framework which would just wrap a generator function in the appropriate response class for that framework. This shows off both ideas at once: datastar/examples/python/fastapi/app.py Lines 86 to 96 in 9155103
|
My instinct on this is to wait, since the decorator is a convenience thing and not a must-have. Since we're unsure, let's build more things with Datastar and see where it goes. If we still think it is a good idea a bit down the road, we can always add this sort of thing later. There is no cost to the SDK to wait, since users still have a way to do the same thing as the decorator accomplishes. |
What do you think about the implicit merge fragments and signals returns? Those could be implemented completely separate from the decorator |
Allow fasthtml to use starlette decorator
a62da60
to
847209b
Compare
Okay, I split the implicit merge fragments/signals away from the decorator. The implicit wrapping now works with any of the frameworks without any decorator, and we can consider the two different ideas in this PR separately. Main post updated to reflect this as well. |
I've separated this PR into two separate ideas for discussion and consideration:
ServerSentEventGenerator.merge_fragment
Similarly a dictionary would implicitly be a merge_signals.Putting this up as a draft for discussion before more work. Some questions to answer:
sse_generator
?TODO if we like this:
Do a fasthtml decorator. The starlette one would work, but it needs the special bit to turn the result from fasthtml stuff into html.