An Electron-like library for Python using pywebview
Project description
Banner: pytron.png
Pytron
Pytron is a modern framework for building desktop applications using Python for the backend and web technologies (React, Vite) for the frontend. It combines the power of Python's ecosystem with the rich user interfaces of the web.
Features
- Type-Safe Bridge: Automatically generate TypeScript definitions (
.d.ts) from your Python code. - Reactive State: Synchronize state seamlessly between Python and JavaScript.
- Advanced Serialization: Built-in support for Pydantic models, PIL Images, UUIDs, and more.
- System Integration: Native file dialogs, notifications, and shortcuts.
- Developer Experience: Hot-reloading, automatic virtual environment management, and easy packaging.
Prerequisites
- Python 3.7+
- Node.js & npm (for frontend development)
Quick Start
-
Install Pytron:
pip install pytron-kit
-
Initialize a New Project: This command scaffolds a new project, creates a virtual environment, installs dependencies, and sets up a frontend.
# Default (React + Vite) pytron init my_app # Using a specific template (vue, svelte, next, etc.) pytron init my_app --template next
Supported templates:
react(default),vue,svelte,next(Next.js),vanilla,preact,lit,solid,qwik. -
Run the App: Start the app in development mode (hot-reloading enabled).
- Windows:
run.bat - Linux/Mac:
./run.sh
Or manually:
pytron run --dev
- Windows:
Core Concepts
1. Exposing Python Functions
Use the @app.expose decorator to make Python functions available to the frontend.
from pytron import App
from pydantic import BaseModel
app = App()
class User(BaseModel):
name: str
age: int
@app.expose
def get_user(user_id: int) -> User:
return User(name="Alice", age=30)
app.generate_types() # Generates frontend/src/pytron.d.ts
app.run()
2. Calling from Frontend
Import the client and call your functions with full TypeScript support.
import pytron from 'pytron-client';
async function loadUser() {
const user = await pytron.get_user(1);
console.log(user.name); // Typed as string
}
3. Reactive State
Sync data automatically.
Python:
app.state.counter = 0
JavaScript:
console.log(pytron.state.counter); // 0
// Listen for changes
pytron.on('pytron:state-update', (change) => {
console.log(change.key, change.value);
});
4. Window Management
Control the window directly from JS.
pytron.minimize();
pytron.toggle_fullscreen();
pytron.close();
Configuration (settings.json)
Pytron uses a settings.json file in your project root to manage application configuration. This keeps your code clean and separates config from logic.
Example settings.json:
{
"title": "My Awesome App",
"pytron_version": "0.1.5",
"frontend_framework": "react",
"width": 1024,
"height": 768,
"resizable": true,
"frameless": false,
"easy_drag": true,
"url": "frontend/dist/index.html",
"icon": "assets/icon.ico",
"version": "1.0.0"
}
- title: The window title and the name of your packaged executable.
- pytron_version: The version of Pytron used to create the project (used for compatibility checks).
- frontend_framework: The framework used (e.g., "react", "next").
- icon: Path to your application icon (relative to project root). Supports
.ico(preferred) or.png. - url: Entry point for the frontend (usually the built
index.html). - width/height: Initial window dimensions.
Packaging
Distribute your app as a standalone executable. Pytron automatically reads your settings.json to determine the app name, version, and icon.
-
Build:
pytron packageThis uses PyInstaller to bundle your app. It will:
- Use the
titlefromsettings.jsonfor the executable name. - Use the
iconfromsettings.jsonfor the app icon. - Automatically exclude
node_modules. - Include your
settings.jsonand frontend assets.
- Use the
-
Create Installer (NSIS):
pytron package --installer
CLI Reference
pytron init <name> [--template <name>]: Create a new project.--template: Frontend framework to use (default:react). Supportsnext,vue,svelte, etc.
pytron run [--dev]: Run the application.pytron package [--installer]: Build for distribution (usessettings.json).pytron info: Show environment and project details.pytron build-frontend <folder>: Build the frontend app.
Happy Coding with Pytron!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytron_kit-0.1.6.tar.gz.
File metadata
- Download URL: pytron_kit-0.1.6.tar.gz
- Upload date:
- Size: 1.7 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5230a491e0489502f47405b6859aafcf8480be4b32109b5be54d96c3602259d3
|
|
| MD5 |
737b35c581445c5735e13f934c0b8e10
|
|
| BLAKE2b-256 |
2902c90f6498f6b509a418f6a7a40e4b44c866d6f1db4f4d2a16d871ab5047af
|
File details
Details for the file pytron_kit-0.1.6-py3-none-any.whl.
File metadata
- Download URL: pytron_kit-0.1.6-py3-none-any.whl
- Upload date:
- Size: 1.7 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
916575e0f8c463d01ca903589f3141c7e7b2133b8d31e7dea1c40769d6b7712e
|
|
| MD5 |
52dbec60914d7f7d4a5ac9ac8e1a5e33
|
|
| BLAKE2b-256 |
811c72c638907fdf7c50bc5e500eb395e3da224220947d8aacd7f9eb3c55916d
|