Skip to content

A starter template for creating a GUI frontend with a JavaScript web framework via Vite for a Python backend via Eel.

License

Notifications You must be signed in to change notification settings

guillaume-mueller/python-eel-vite-starter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Eel with Vite starter template, Vue.js variant

A starter template for creating a GUI frontend with a JavaScript web framework via Vite for a Python backend via Eel.

While this template uses Vue.js, there's a similar one for Svelte available in another branch.

Key features

  • Structured as a launchable Python package with some simple process managing to automate the interoperability between Eel and Node.js
  • Development mode with Vite's Hot Module Replacement (HMR)
  • Bidirectional communication in both development and production modes
  • Focused on understanding how this works to keep full control instead of packaging a pretended solution

Tested versions

  • Linux Mint 22.1 (based on Ubuntu 24.04)
  • Python 3.12.3
  • Eel 0.18.1
  • Chromium 135.0.7049.95
  • Node.js 22.14.0
  • Vite 6.3.2
  • Vue.js 3.5.13

Setup

  1. Install Python dependencies:

    pip install --requirement=requirements.txt
  2. Create the Vite template with Node.js package manager:

    cd app
    npm create vite@latest

    Choose :

    • Project name: frontend
    • Framework: Vue
    • Variant: JavaScript
  3. In app/frontend/index.html, add to <head>:

    <script type="text/javascript" src="/eel.js"></script>
  4. Update app/frontend/vite.config.js:

    import { defineConfig, loadEnv } from 'vite'
    import vue from '@vitejs/plugin-vue'
    
    // https://vite.dev/config/
    export default defineConfig(({ command, mode }) => {
        const env = loadEnv(mode, './..', '');
        return {
            plugins: [vue()],
            build: { outDir: env.BUILD_DIR },
            ...(command === 'serve' && {  // dev mode config
                server: {
                    host: env.DEV_HOST,
                    port: Number(env.DEV_PORT),
                    proxy: {
                        '/eel': {
                            ws: true,  // WebSocket
                            target: {
                                host: env.EEL_HOST,
                                port: env.EEL_PORT
                            }
                        }
                    }
                }
            })
        };
    });

Testing Communication

  1. In app/frontend/src/components/HelloWorld.vue, add to <script setup>:

    const eel = window.eel;
    const msg_to_python = ref("");
    
    function send_to_js(message) {
        console.log("Message received from Python: " + message);
    }
    window.eel.expose(send_to_js, 'send_to_js');  // ⚠️ must be called via `window.` and must get the name repeated as a string because the production build changes the functions names
  2. Add to <template>:

    <input type="text" placeholder="Message to Python" v-model="msg_to_python"/>
    <button @click="eel.send_to_python(msg_to_python)">Send to Python</button>

Production mode

  1. Run from project root:

    python -m app prod
  2. Test:

    • Check the Python to JS message in DevTools (F12).
    • Send a message from JS to Python with the user interface and check the console output of Python.

Development mode

  1. Run from project root:

    python -m app dev
  2. Test communication as in production mode.

  3. Modify <template> content in HelloWorld.vue to test the HMR feature.

Known Issues

  1. Memory leak: Eel 0.18.1 has a memory leak for Python exposed function. Apply this fix if needed.

  2. Performance: For sustained data streaming, the JSON constrain of Eel may be a bottleneck. Consider using Flask-SocketIO for binary format with a similar ease of use.

About

A starter template for creating a GUI frontend with a JavaScript web framework via Vite for a Python backend via Eel.

Topics

Resources

License

Stars

Watchers

Forks

Languages