A modern template for creating desktop applications with Python (backend) and Svelte 5 + TypeScript (frontend).
git clone <your-repo>
cd template-pywebview-svelte
pip install -r requirements.txt
# With pnpm (recommended)
pnpm install
# Or with npm
npm install
python run.py
python dev.py
The 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:watch
template-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=800
Modify 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
/api/health - Check API status/api/message - Get current message/api/message - Update message/api/items - Get items list/api/items - Add new item/api/items/{id} - Delete itemStyles 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.py
To create an executable with PyInstaller:
# Windows
build.bat
# Linux/Mac
python build_exe.py
The executable will be created in the dist/ folder with all files integrated.
Port already in use error
config.py or app.pyMissing dependencies
pip install -r requirements.txt and pnpm installFrontend build error
pnpm install then pnpm run buildVite server not accessible from outside
dev.py script automatically uses --hostlocalhost:3000 doesn't work, use the IP displayed by Vitepywebview error with unsupported parameters
minimizable and maximizable are not supportedESLint or Pylint errors
pylint --disable=W0212 app.pyconfig.pyThis project is licensed under the MIT License. See the LICENSE file for more details.