Skip to content

Latest commit

 

History

History
76 lines (58 loc) · 3.22 KB

README.md

File metadata and controls

76 lines (58 loc) · 3.22 KB

aiodesktop

Latest version on PyPi Supported Python versions CircleCI

A set of tools which simplify building cross-platform desktop apps with Python, JavaScript, HTML & CSS.

Features

In contrast to typical desktop GUI frameworks such as tkinter, wxPython, PyQt or Kivy:

  • does not define own widgets/layout system (Kivy, Qt, wx), simply use a browser as a platform which already provides those things
  • your app is client-server and cross-platform by design, different devices may use it simultaneously

Compared to existing alternatives such as Eel, async-eel and guy:

  • runs on asyncio instead of threads or gevent greenlets
  • highly customizable aiohttp server
  • no global state / singleton API

Install

Install from pypi with pip:

pip install aiodesktop

Hello, World!

import aiodesktop

class Server(aiodesktop.Server):
    async def on_startup(self):
        aiodesktop.launch_chrome(self.start_uri)
    
    # Use `expose` decorator to mark method as visible from JS
    @aiodesktop.expose
    async def get_string(self):
        # Use `await self.js.xxx()` to call JS functions from Python 
        return 'Hello, ' + await self.js.getWorld()

bundle = aiodesktop.Bundle()
server = Server(
    bundle=bundle,
    init_js_function='onConnect',
    index_html='''<html><body><script>
    async function onConnect(server) {                        
        // Exposing JS function to python        
        server.expose({
            async getWorld() {
                return 'World!'
            }
        });        
        
        // Use `await server.py.xxx()` to call Python methods from JS
        document.body.innerHTML += await server.py.get_string(); 
    };
</script></body></html>''',
)
server.run()

See example/ for a slightly more complicated app with:

  • static files
  • pyinstaller executable
  • JS & webpack
  • https