FastAPI HTTP Requests in Streamsync App #112
Replies: 5 comments 4 replies
-
can you show the code |
Beta Was this translation helpful? Give feedback.
-
@SurajRaika Thanks for the response! I don’t have any specific code to share, it’s more of a general question. Basically, my experience with FastAPI is that the script would look something like:
However, with StreamSync, some script on the backend is automatically creating the FastAPI app so I can’t reference it in my script with the @app.method decorator. Trying to figure out how I could get a handle on the FastAPI app that streamsync creates so I could write those get, post, put, etc. methods using the decorator, and use those functions as the event handler. |
Beta Was this translation helpful? Give feedback.
-
I've been looking for a hook or a way to grab the asgi app from application code. I didn't find any. All the ways I've found involve building your own running endpoint or to run a server inside or above. I don't recommand any of those approach. Maybe someone will have a great solution without doing it and without changing the streamsync code. |
Beta Was this translation helpful? Give feedback.
-
@FabienArcellier Thanks for the response - that’s been my experience as well! It’s the one thing keeping this from being the perfect solution for our data science web apps. @ramedina86 - Do you know of an approach for this? Appreciate any guidance you can provide! |
Beta Was this translation helpful? Give feedback.
-
Hello everyone I think you'd be fine mounting an ASGI server inside another one, as shown on the Custom server documentation. It mounts different Streamsync instances on Does this cover this requirement? If not, please let me know. |
Beta Was this translation helpful? Give feedback.
-
Hi all -
Apologies in advance if this is a very 101-level question. I’m a data scientist hoping to use Streamsync to create basic web apps and website POC’s so non-technical users can interact with data and ML models. I have only a basic understanding of web development so Streamsync seems like a fantastic solution.
I’ve been able to design some sites using the builder and am able to track state, update components using state, and perform transformations using event handlers in python functions. What I haven’t been able to figure out yet is how to use the FastAPI functionality to make http requests to external services like model endpoints or external databases. I’ve played around with FastAPI before and know it’s pretty simple to implement when you’re instantiating the FastAPI app in the script (you can just use the decorators like @app.post(“/“), etc.) but I’m not sure how to do this from my main.py script when the app is being generated by streamsync.
I wondered if the solution was to use the custom serving options in the documentation but I’m getting a multi threading error when I try that so figured I’d ask.
Sorry again if this is a silly question and thanks in advance for any guidance!
Beta Was this translation helpful? Give feedback.
All reactions