A modern template for creating desktop applications with Python (backend) and Svelte 5 + TypeScript (frontend).
- Python Backend with Flask and pywebview
- Svelte 5 Frontend with TypeScript
- REST API for frontend-backend communication
- Real-time state management
- Automated build scripts
- Development mode with hot-reload and external connections
- Automated linting and formatting (ESLint 9 + Prettier)
- Flexible configuration via environment variables
- Python 3.8+
- pywebview - Desktop window creation
- Flask - Web framework
- Flask-CORS - CORS handling
- Svelte 5 - Modern JavaScript framework
- TypeScript - Static typing
- Tailwind CSS 4.1.x - Utility CSS framework
- Vite - Fast build tool
- Axios - HTTP client
- ESLint 9 - JavaScript/TypeScript linter (flat config)
- Prettier - Code formatter
- Pylint - Python linter
- Python 3.8+
- Node.js 16+
- pnpm
git clone <your-repo>
cd template-pywebview-sveltepip install -r requirements.txt# With pnpm (recommended)
pnpm install
# Or with npm
npm installpython run.pypython dev.pyThe Vite server starts automatically with the --host option to allow external connections. If localhost:3000 doesn't work, use the IP displayed by Vite (e.g., http://172.31.247.210:3000/).
# JavaScript/TypeScript linter (ESLint 9)
pnpm run lint
# Automatic linting error correction
pnpm run lint:fix
# Code formatting with Prettier
pnpm run format
# Format checking
pnpm run format:check
# Python linter (optional)
pylint app.py run.py dev.py build_exe.py config.py# Frontend build
pnpm run build
# TypeScript verification
pnpm run check
# Watch mode verification
pnpm run check:watchtemplate-pywebview-svelte/
βββ π src/ # Svelte source code
β βββ π components/ # Svelte components
β β βββ Header.svelte
β βββ π lib/ # Utilities and services
β β βββ api.ts # API service
β βββ App.svelte # Main component
β βββ main.ts # Entry point
β βββ app.css # Global styles
βββ π dist/ # Frontend build (generated)
βββ app.py # Main Python application
βββ config.py # Centralized configuration
βββ run.py # Launch script
βββ dev.py # Development script
βββ build_exe.py # Executable build script
βββ requirements.txt # Python dependencies
βββ package.json # Node.js dependencies
βββ vite.config.ts # Vite configuration (with --host)
βββ tsconfig.json # TypeScript configuration
βββ eslint.config.cjs # ESLint 9 configuration (flat config)
βββ README.md # Documentation
Create a .env file at the project root:
# Flask Configuration
FLASK_ENV=development
FLASK_DEBUG=True
PORT=5000
HOST=127.0.0.1
# Window Configuration
WINDOW_TITLE=PyWebView + Svelte Application
WINDOW_WIDTH=1200
WINDOW_HEIGHT=800Modify settings in config.py or via environment variables:
# In config.py
WINDOW_TITLE = 'Your Application'
WINDOW_WIDTH = 1200
WINDOW_HEIGHT = 800
WINDOW_MIN_SIZE = (800, 600)Or via the .env file:
WINDOW_TITLE=Your Application
WINDOW_WIDTH=1200
WINDOW_HEIGHT=800- GET
/api/health- Check API status
- GET
/api/message- Get current message - POST
/api/message- Update message
- GET
/api/items- Get items list - POST
/api/items- Add new item - DELETE
/api/items/{id}- Delete item
Styles are organized in src/app.css with CSS variables:
:root {
--primary-color: #3498db;
--secondary-color: #2ecc71;
--danger-color: #e74c3c;
/* ... other variables */
}Each component is in src/components/ and can be customized according to your needs.
Add new endpoints in app.py:
@app.route('/api/your-endpoint')
def your_function():
return jsonify({'data': 'your_data'})# Build frontend
pnpm run build
# Launch application
python run.pyTo create an executable with PyInstaller:
# Windows
build.bat
# Linux/Mac
python build_exe.pyThe executable will be created in the dist/ folder with all files integrated.
-
Port already in use error
- Change the port in
config.pyorapp.py
- Change the port in
-
Missing dependencies
- Verify all dependencies are installed
- Run
pip install -r requirements.txtandpnpm install
-
Frontend build error
- Verify Node.js is installed
- Run
pnpm installthenpnpm run build
-
Vite server not accessible from outside
- The
dev.pyscript automatically uses--host - If
localhost:3000doesn't work, use the IP displayed by Vite
- The
-
pywebview error with unsupported parameters
- Some parameters like
minimizableandmaximizableare not supported
- Some parameters like
-
ESLint or Pylint errors
- ESLint 9 uses the new "flat config" configuration
- Pylint errors can be fixed with
pylint --disable=W0212 app.py
- Enable debug mode in
config.py - Check the console for errors
- Use browser development tools
- Fork the project
- Create a branch for your feature
- Commit your changes
- Push to the branch
- Open a Pull Request
This project is licensed under the MIT License. See the LICENSE file for more details.