Hacker News new | past | comments | ask | show | jobs | submit login
Show HN: Pywebview 5 (flowrl.com)
126 points by kissaprofeetta 9 months ago | hide | past | favorite | 33 comments
I am happy to announce a new major version of pywebview



I used Pywebview for a project and had to contribute a few bug fixes to have it working right but it's been a pleasure to work with. Especially since it is fully supported by pyinstaller to build stand-alone executables that can then be distributed and easily used (simple double click) by people who otherwise wouldn't open a terminal, activate a python virtual environment, and then launch the program.


Thanks for the kinds words and your contributions. :)


We tried using pywebview for a cross-platform desktop app when it was version 3.x and some of the features were limited, especially when it came to systray interactions. Will have to try it out again. In the end, for that specific project, we ended up settling on NeutralinoJS. Wails was another big contender but due to limited GoLang resources in-house, we decided not to use it. Reference: https://neutralino.js.org/


Author here. Systray icon is not supported natively, but you can create one with a third party pystray package. Here is an example https://pywebview.flowrl.com/examples/pystray_icon.html


I've been using Pywebview for a couple of internals tools at work, on windows desktops. I had to install Edge WebView2 (cf. https://developer.microsoft.com/en-us/microsoft-edge/webview... ) because it wouldn't work without it, but apart from this, very easy to use.

Happy to see further improvements to this library !


What are the advantages of using something like Pywebview compared to opening the user’s browser to localhost?


You get to control the chrome a bit more - with Pywebview you can open something that looks like a regular application window, with the fact that it's HTML+CSS+JavaScript a hidden (from the user) implementation detail.

You can make Python functionality available to your custom JavaScript via a bridge. The bridge goes both ways - your Python application can trigger JavaScript to run inside the visible windows too.

You can add application menus.


Thanks! Are there any drawbacks to Pywebview compared to a browser?


Probably loads. It's an extra dependency so it adds complexity (though it does seem to be very cleanly designed from what I've seen so far). Stuff people do in Pywebview won't be added to their browser history, doesn't get access to their existing cookies, presumably doesn't work with password managers and browser extensions.

But if you want to give people a separate app experience it looks like a great option to me.


Author here. Here are top advantages from the top of my head

* pywebview hides its browser nature. Right click, text select, shortcut keys, swipe gestures etc are disabled by default.

* window manipulation functionality. Move, resize, minimize, maximize etc

* native file dialog support. These are more capable than browser's own file dialogs.

* native application menu

* with the new version you can get a full file path on file drag and drop. This is not possible in browser.

* two way Javascript-Python bridge. You can invoke Javascript from Python and Python from Javascript

* If Javascript is not your cup of tea, you can do quite a bit in pure Python.


I really hate it when text select is disabled. Often very useful, e.g. for reporting.


Conversely, it can also be very annoying when you accidentally select some of the UI text and you have to manually deselect it (or maybe you can't deselect it).


Text select is user controlled option for the whole window or you can enable text select for individual elements with CSS.


in my case, having access to the local filesystem through a non-crippled API (looking at you JS...) was invaluable.


Very nice! Congrats on the release.

Side note: I find it funny how we go to such lengths in order not to write JavaScript.


Actually, using this the chances are you'll still write JS. The examples are all JS-based.

Most of this project seems to be about replacing Electron specifically.


Are there any sizable examples without Javascript at all?

Also this uses a whole lot of custom code (and some DLLs vendored and created from the interop-native-packages...) to hook up to native Webviews (which might be fine for simple things, but so is tkinter), so this is not electron, where you get a specific verson of blink/whatever and build on that.

In addition, it uses heavy toolkits to get the webview (i.e. Kivy on Android and Qt on Linux) – all of which incidentally also support all the platforms. EDIT: it doesn't package them though... So why multiply your problems: from GUI-framework Y on platform (X1,X2,X3) to GUI-framework (Y1,Y2,Y3)on platform (X1,X2,X3) using render-engine (Z1,Z2,Z3).

If you want to use the platform-browser anyway: why not create a small native shim (with Tkinter everywhere but Android) to control your server and package that?

To end on a very positive note: this is a herculean collection of tools to deploy Python GUIs on nearly any platform and as such seems like a very nice ressource if you want to do that!


Using Pywebview you can either use a "normal" web backend, e.g., using Flask to make a backend HTTP API, or you can expose Python code to make it callable "directly" (a more correct term would be "transparently") from JavaScript on the frontend side. In the latter case it's quite useful be able to update the DOM directly from Python :).


I'm not. I see the Javascript guy, the GO guy, but I am surprised not to see the Rust guy, probably just running late though.


This post isn't specifically recommending it as a substitute, but it references Tauri, which is Rust [0].

[0] https://news.ycombinator.com/item?id=39689206


Thanks, this feels like Tauri but with Python (correct me of wrong).

Hoping to give it a try soon!


Author here. Yes you are correct with the exception that pywebview predates Tauri by five years.


This looks really neat! I'm just about to start a desktop application project, so I've found this at the perfect time.

Is this production ready? I need to target Windows and MacOS with a high level of stability.


Author here. I have maintained pywebview for almost ten years, so yeah I would say it is production ready at this point :) New major version brings its own share of bugs, but most of those should have been ironed since 5.0


I would recommend wails (https://wails.io/) which is the same thing but for Go.

Nothing against this project it's just Python is not an optimal technology for shipping self-contained desktop apps.

You'll have to bundle the whole of Python distro which is very bloaty.

A Go will compile to a statically linked executable that only contains the code actually used in the app. Still not tiny but probably 10x smaller than packaged Python app.

And I used wails so can vouch that it works.

There's also an option for Rust (which I haven't used because I don't particularly want to learn Rust).


> which I haven't used because I don't particularly want to learn Rust

This is a good reason to not recommend libraries for other languages as a substitute. People are interested in pywebview because it's written for Python. They don't want to learn Go any more than you want to learn Rust.

> Nothing against this project it's just Python is not an optimal technology for shipping self-contained desktop apps.

"Optimal" is relative, and varies depending on a lot of factors that you don't have context for for OP's project. Even setting aside the value of being able to use a language you already know (which is hard to overstate), there are reasons you might want to use Python over Go.

For example: the last desktop app that I started integrates with a bunch of ML/LLM libraries that are, unsurprisingly, primarily written in and for Python. I could use Go and dive into FFI/IPC for the Python code, or I can just write the whole thing in Python and pywebview and figure out distribution [0]. I chose the latter.

[0] https://pyinstaller.org/en/stable/


Bundling Python isn't too bad if you find the right tools for it.

I really like https://github.com/indygreg/python-build-standalone and https://github.com/indygreg/PyOxidizer

A bundled, built standalone Python can be 16 to 32MB (including the full standard library, which you can strip down to just the bits you use to save size). Not tiny, but probably not worth switching programming languages over.


> You'll have to bundle the whole of Python distro which is very bloaty.

Python's embeddable package (for 64-bit Windows, available on the download page) is 23 MB uncompressed or 10.5 MB zipped. Although I'm sure Go can create smaller apps, I wouldn't call it "very bloaty".


If you love Python, but envy the compiled-binary-ness of Go, you should check out Nim, and Nim bindings for Webview:

https://github.com/neroist/webview

(Obviously, Nim is not Python, but I like it. It does feel like a compiled, fast Python. And no disrespect to Pywebview, it's great, too.)


There is a difference between speed and productivity and if you need to learn Go that can be a bigger problem than inefficiency. Also you should have a reason other that to change programming languages like this library versus walls like an actual speed test..:


Are wails and pywebview bloaty? Do they bundle Chrome?


No. They use whatever webview OS provides.

On Windows it's webview that is Edge (based on Chrome).

On Mac it's webview based on Safari.

They re-use the executable that is already installed in the OS.

They don't provide all the features that Electron does but you can do anything that a modern browser can do + add OS specific things with backend code (written in Go or Python or Rust, depending on which project you use).


You can force it to use CEF, but otherwise uses what the OS/DE provides.

https://pywebview.flowrl.com/guide/web_engine




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: