| 27 |
<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/3.7/guide/" class="nav-link router-link-active"> |
| 39 |
<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav> <ul class="sidebar-links"><li><section class="sidebar-group depth-0"><p class="sidebar-heading"><span>Basics</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/3.7/guide/installation.html" class="sidebar-link">Installation</a></li><li><a href="/3.7/guide/usage.html" class="sidebar-link">Usage</a></li></ul></section></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading open"><span>Development</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/3.7/guide/api.html" class="sidebar-link">API</a></li><li><a href="/3.7/guide/architecture.html" aria-current="page" class="active sidebar-link">Application architecture</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/3.7/guide/architecture.html#local-web-server" class="sidebar-link">Local web server</a></li><li class="sidebar-sub-header"><a href="/3.7/guide/architecture.html#serverless" class="sidebar-link">Serverless</a></li></ul></li><li><a href="/3.7/guide/debugging.html" class="sidebar-link">Debugging</a></li><li><a href="/3.7/guide/interdomain.html" class="sidebar-link">Interdomain communication</a></li><li><a href="/3.7/guide/freezing.html" class="sidebar-link">Freezing</a></li><li><a href="/3.7/guide/security.html" class="sidebar-link">Security</a></li><li><a href="/3.7/guide/virtualenv.html" class="sidebar-link">Virtual environment</a></li><li><a href="/3.7/guide/renderer.html" class="sidebar-link">Web engine</a></li></ul></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="application-architecture"><a href="#application-architecture" class="header-anchor">#</a> Application architecture</h1> <p>There are two ways to build your application using <em>pywebview</em>:</p> <ol><li>By running a local web server</li> <li>Serverless with <em>pywebview</em>'s JS API or <code>window.expose</code> and serving local files.</li></ol> <h2 id="local-web-server"><a href="#local-web-server" class="header-anchor">#</a> Local web server</h2> <p>Running a local web server is a traditional way to build your local application. This way everything is served from a local web server and <em>pywebview</em> points to the URL provided by the server. In this model the server is responsible for both serving static contents and handling API calls. When building an application using a web server, you should protect your API calls against CSRF attacks. See <a href="/3.7/guide/security.html">security</a> for more information.</p> <p>See an example <a href="https://github.com/r0x0r/pywebview/tree/master/examples/flask_app" target="_blank" rel="noopener noreferrer">Flask-based application<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></p> <p><strong>Pros</strong>:</p> <ul><li>Ability to pack an existing web application as a local one.</li> <li>Easier debugging with an external browser.</li></ul> <p><strong>Cons</strong></p> <ul><li>Has to rely on a third party server software for client-server communication.</li> <li>Security considerations must be taken into account</li></ul> <h2 id="serverless"><a href="#serverless" class="header-anchor">#</a> Serverless</h2> <p>Another way to build an application is to use <em>pywebview</em>'s provided JS API or <code>windows.expose</code> and serve static files locally.</p> <p><em>pywebview</em> offers a simple built-in web server that is good enough for serving local files. To use a local web server, set url to a local file and start the application with <code>webview.start(http_server=True)</code>. Note that the built-in HTTP server serves only local files and does not offer any API calls. Refer to <a href="/3.7/guide/interdomain.html">interdomain communication</a> for details on how to pass data between Python and Javascript.</p> <p>See an example <a href="https://github.com/r0x0r/pywebview/tree/master/examples/todos" target="_blank" rel="noopener noreferrer">serverless application<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></p> <p><strong>Pros</strong>:</p> <ul><li>No external dependencies</li> <li>More straightforward architecture</li> <li>No risk of CSRF attacks</li></ul> <p><strong>Cons</strong></p> <ul><li>Debugging has to be done inside the application using provided debugging tools</li> <li>EdgeHTML cannot serve local files.</li></ul></div> <footer class="page-edit"><div class="edit-link"><a href="https://github.com/r0x0r/pywebview/edit/docs/docs/guide/architecture.md" target="_blank" rel="noopener noreferrer">Help us improve this page!</a> <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></div> <!----></footer> <div class="page-nav"><p class="inner"><span class="prev"> |