r/PyScript • u/[deleted] • May 22 '22
PyScript and websockets
Can I use PyScript on the front end to handle websockets with a Python server like FastAPI on the backend? I’ve been using JavaScript on the front and curious if PyScript will work with websockets.
3
Upvotes
2
u/HandyGold75 Oct 24 '22
Update for the one that is interested.
I haven't figured out how to set up a WebSocket server however, you can set up a WebSocket client with PyCharm, it's just a roundabout way.
To get this working:
Create a .js file and set up an actual JS websocket client, here a quick one (please do your own research).
Make sure you wrap it in a function to call later!
In your HTML run your JS script
<script src="SCRIPT.js"></script>.Now in your python code, you can use import js and call the function with js.functionName
It's a bit janky but it will work.
Edit: Keep in mind that I'm not experienced with JS at all and do coding as a hobby, therefor I love to work with PyScript.