Application architecture
Application architecture
There are several way to build your application using pywebview:
Pure web server
- The most simple case is pointing to a url. This requires a running web server either remotely or locally
webview.create_window('Simple browser', 'https://pywebview.flowrl.com')
webview.start()
If you point to a local web server, you can start an external HTTP server in a background thread manually and or giving a WSGIRef server instance to the url parameter.
server = Flask(__name__, static_folder='.', template_folder='.')
webview.create_window('My first pywebview application', server)
webview.start()
See a complete example Flask-based application
When using a local web server, you should protect your API calls against CSRF attacks. See security for more information.
While the file://
protocol is possible, its use is discouraged as it comes with a number of inherit limitations and is not well supported.
JS API with internal HTTP server
Another approach is using JS API bridge and serving static content with a built-in HTTP server. JS API bridge allows communication between Python and Javascript domains without a web server. Thje bridge can be created either with create_window(..., js_api=Api())
or or window.expose
function. To serve static contents, set entrypoint url to a local relative path. This will start a built-in HTTP server automatically. For more details on communication between Python and Javascript refer to interdomain communication. See an example serverless application for a complete implementation.
Serverless
- Finally you can do without a web server altogther by loading HTML using
webview.create_window(...html='')
orwindow.load_html
. This approach has got limitations though, as file system does not exist in the context of the loaded page. Images and other assets can be loaded only inline using Base64.