# pywebview — Lightweight Python GUI with Web Technologies > A cross-platform Python library that creates native GUI windows with embedded web views, letting you build desktop applications using HTML, CSS, and JavaScript for the frontend with Python for the backend. ## Install Save in your project root: # pywebview — Lightweight Python GUI with Web Technologies ## Quick Use ```bash pip install pywebview ``` ```python import webview def api_hello(): return "Hello from Python!" window = webview.create_window("My App", "https://example.com") webview.start() ``` ## Introduction pywebview provides a simple way to create desktop GUI applications in Python using web technologies for the interface. Instead of bundling a full browser engine, it uses the system's native webview component (WebKit on macOS, WebView2 on Windows, WebKitGTK on Linux), keeping your application lightweight. ## What pywebview Does - Creates native desktop windows with an embedded web renderer - Exposes Python functions to JavaScript for bidirectional communication - Supports loading local HTML files, remote URLs, or inline HTML content - Provides a built-in HTTP server for serving local web assets - Handles file dialogs, window management, and system tray integration ## Architecture Overview pywebview uses the platform's native webview: Cocoa WebKit on macOS, Microsoft Edge WebView2 on Windows, and WebKitGTK or QtWebEngine on Linux. The Python process creates the window and optionally starts a local HTTP server. A JavaScript bridge lets frontend code call Python functions and receive results. All rendering happens in the native webview process, so the Python process handles only application logic and API calls. ## Self-Hosting & Configuration - Install with pip; no additional build tools required for basic usage - On Windows, WebView2 runtime is included with Windows 10/11 or installable separately - On Linux, install the webkitgtk package from your distribution's repository - Configure window properties like size, resizability, and transparency at creation time - Use the built-in server or bring your own Flask, FastAPI, or Django backend ## Key Features - Uses native webview rather than bundling Chromium, resulting in minimal overhead - Python-to-JavaScript API bridge with automatic JSON serialization - Multiple window support with independent content and event handling - File open and save dialogs through native OS interfaces - Frameless and transparent window modes for custom UI designs ## Comparison with Similar Tools - **Electron** is more powerful but bundles Chromium, adding 150 MB+; pywebview uses the system webview - **Eel** is a similar Python library but uses Chrome in app mode rather than native webview - **Tauri** uses Rust for the backend; pywebview keeps everything in Python - **NiceGUI** and **Streamlit** serve UIs in a browser tab; pywebview opens a native window - **Tkinter** and **PyQt** require learning their widget APIs; pywebview lets you use standard HTML/CSS/JS ## FAQ **Q: What is the minimum application size?** A: Since pywebview uses the system webview, your distribution is just the Python code and assets. A packaged app with PyInstaller can be as small as 15-30 MB. **Q: Can I use frontend frameworks like React or Vue?** A: Yes. Build your frontend with any framework and either serve the built files through pywebview's local server or load them from a dist folder. **Q: Does pywebview work with virtual environments?** A: Yes. Install pywebview in any virtualenv or conda environment as you would any other Python package. **Q: How do I package the app for distribution?** A: Use PyInstaller, cx_Freeze, or Nuitka to bundle the Python code, pywebview, and your web assets into a standalone executable. ## Sources - https://github.com/nicedream/pywebview - https://pywebview.flowrl.com --- Source: https://tokrepo.com/en/workflows/asset-9fbf37a7 Author: AI Open Source