4 ms·
> I'm building the UI using ElectronJS and Svelte, whilst the backend is a separate Python project. Thanks for sharing this. I have a relatively simple Python
by klenwell 6y ago
> I'm building the UI using ElectronJS and Svelte, whilst the backend is a separate Python project.
Thanks for sharing this. I have a relatively simple Python script that I'm trying to package for a non-technical Windows user so, as someone whose experience skews toward web development, your comment caught my attention.
I just googled "electron svelte python" and found this write up:
https://medium.com/@abulka/electron-python-4e8c807bfa5e https://medium.com/@abulka/electron-python-4e8c807bfa5e
Which references this Github repo:
https://github.com/fyears/electron-python-example https://github.com/fyears/electron-python-example
It all sounds pretty brittle. How are you managing communication between your ElectronJS frontend and Python backend? Any references you recommend?
- petargyurov 6y agoI think I came across that as well. I didn't like it. As far as I understand, there are two ways to handle communication between the Python and ElectronJS: 1) Use inter-process communication. Basically, your Python app outputs to stdin and your Electron app consumes the output. Also works the other way. This is what I went with. 2) Use a Flask (or equivalent) local web server and have your app send requests to it. I find method 2) a bit hacky and unintuitive for a desktop app. If you are planning on hosting your backend in the cloud this would be a decent solution, but I am not. I had already done some work to turn my Python app into a standalone CLI tool using `click` [0] which made the interaction with ElectronJS very simple. I used `python-shell` [1] for the inter-process communication. I do think that I might not need this once I package my Python app into an .exe -- then Electron should be able to interact with it in some way without caring that it's built in Python. You can take a look at my repo here, though it's still in its infancy: https://github.com/petargyurov/megadetector-gui https://github.com/petargyurov/megadetector-gui [0] https://click.palletsprojects.com/en/7.x/ https://click.palletsprojects.com/en/7.x/ [1] https://www.npmjs.com/package/python-shell https://www.npmjs.com/package/python-shell
- vlovich123 6y agoWhy not use something like gRPC or cap’n’proto to make the request/response stuff easier to manage?
- Aeolun 6y agoBecause it still requires request and response. The way you are doing request/response, or encoding the data is immaterial.
- hcrad 6y agoAs far as quickly standing up an effective gui for python, I'd recommend gooey. https://github.com/chriskiehl/Gooey https://github.com/chriskiehl/Gooey
- sususu 6y agoSome time ago I helped build a software that heavily used some python GIS libraries (GDAL, rasterio, etc) and we needed a UI for some windows users. We chose cefpython[1] to the job, as we could interface easily between the python and JS parts. The development experience is not so polished as of Electron though. Nonetheless, is a great project and not so difficult to use, although not perfect, it worked perfectly for our needs. [1] https://github.com/cztomczak/cefpython https://github.com/cztomczak/cefpython