Skip to main content

An Electron-like library for Python to build Cross Platform Apps

Project description

Pytron

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.

New / Notable Features (latest)

  • Daemon & System Integration: New hide/show APIs and system_notification support allow apps to run as daemons, show/hide windows programmatically, and emit native notifications across Windows/macOS/Linux.
  • Taskbar / Dock Progress & Icons: APIs to set taskbar progress and update the application icon at runtime (Windows taskbar, macOS Dock badge, basic Linux support).
  • Native Dialogs: Cross-platform native file dialogs (open/save/folder) using the OS tools (Windows common dialogs, macOS AppleScript, Linux zenity/kdialog) are exposed to the Webview layer.
  • Message Boxes: Unified message_box with cross-platform fallbacks (native MessageBox on Windows, zenity/kdialog on Linux, AppleScript on macOS).
  • Packaging Improvements: pytron package can now bundle a splash screen into PyInstaller builds (--splash support), and the Windows installer compression has been updated for better AV compatibility.
  • Serializer Enhancements: PytronJSONEncoder gained broader support (Pydantic models, PIL images -> data URIs, dataclasses, enums, timedeltas, complex numbers, slots, and iterable fallbacks) for safer frontend bridging.
  • Platform Interface Expanded: Platform backends now provide richer capabilities (notifications, dialogs, icon/app-id management, tray/daemon helpers).

Prerequisites

  • Python 3.11+ (3.7+ minimum supported)
  • Node.js & npm (for frontend development)

Linux (Ubuntu/Debian) Requirements

Pytron uses a high-performance native engine on Linux that requires GTK3 and WebKit2GTK. Install them with:

# Ubuntu 22.04 / 24.04
sudo apt install libwebkit2gtk-4.1-0 libgtk-3-0

[!NOTE] Pytron-Kit now includes a Linux Schism Guard. You no longer need to install python3-gi or PyGObject for most apps, as the Native Engine handles GLib/GTK isolation automatically to prevent crashes.

Quick Start

  1. Install Pytron: Windows:

    pip install pytron-kit
    

    Linux / macOS (Recommended):

    pipx install pytron-kit
    

    Note: On modern Linux distros (Ubuntu 23.04+), pipx involves less risk of breaking system packages (PEP 668).

  2. Initialize a New Project: This command scaffolds a new project, creates a virtual environment (env/), installs initial 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.

  3. Install project dependencies (recommended): After cloning or when you need to install/update dependencies for the project, use the CLI-managed installer which will create/use the env/ virtual environment automatically:

    # Creates env/ if missing and installs from requirements.txt
    pytron install
    

    Notes:

    • This creates an env/ directory in the project root (if not already present) and runs pip install -r requirements.txt inside it.
    • All subsequent pytron commands (run, package, etc.) will automatically prefer the project's env/ Python when present.
  4. Run the App: Start the app in development mode (hot-reloading enabled). The CLI will use env/ Python automatically if an env/ exists in the project root.

    • Windows: run.bat
    • Linux/Mac: ./run.sh

    Or manually via the CLI:

    pytron run --dev
    

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. any registered function with "pytron_" prefix will be available as pytron_{function_name} and will not be proxied into the pytron object.

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();

5. Development Workflow (--dev)

The development mode in Pytron is designed for modern web development workflows.

pytron run --dev
  • Dual Hot Reloading:
    • Frontend: Pytron detects your npm run dev script (Vite/Next/WebPack) and proxies the window to your local dev server (e.g., localhost:5173). This gives you Hot Module Replacement (HMR)—UI changes update instantly without a reload.
    • Backend: Pytron watches your Python files. If you change backend logic, the Python application performs a Hot Restart automatically.
  • Debug Logging: If debug: true is set in settings.json, Pytron switches to verbose logging, showing bridge messages and binding invocations.
  • Non-Blocking UI: Pytron automatically runs synchronous Python functions in a background thread pool, ensuring that heavy Python tasks never freeze the UI.

Configuration (settings.json)

Pytron uses a settings.json file in your project root to manage application configuration.

Example settings.json:

{
    "title": "pytron app",
    "pytron_version": "0.2.2",
    "frontend_framework": "react",
    "dimensions":[800,600],
    "frameless": false,
    "debug": 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.
  • debug: Set to true to enable verbose logging and dev tools.
  • url: Entry point for the frontend (usually the built index.html). In --dev mode, this is overridden by the dev server URL.
  • icon: Path to your application icon (relative to project root).

UI Components

Pytron provides a set of UI components to help you build a modern desktop application. They have preimplemented window controls and are ready to use.

Usage

npm install pytron-ui

then import the webcomponents into your frontend app

import "pytron-ui/webcomponents/TitleBar.js";
//usage
<pytron-title-bar></pytron-title-bar>
//for react
import { TitleBar } from "pytron-ui/react";
//usage
<TitleBar></TitleBar>

Packaging

Distribute your app as a standalone executable. Pytron automatically reads your settings.json to determine the app name, version, and icon. Note on File Permissions: When your app is installed in Program Files, it is read-only. If your app writes logs or databases using relative paths (e.g., logging.basicConfig(filename='app.log')), it will crash with PermissionError. Pytron Solution: When running as a packaged app, Pytron automatically changes the Current Working Directory (CWD) to a safe user-writable path (e.g., %APPDATA%/MyApp). Your relative writes will safely end up there.

  1. Build:
    pytron package
    

CLI Reference

  • pytron init <name> [--template <name>]: Create a new project.
  • pytron install [package]: Install dependencies.
    • Pin versions in requirements.json.
    • Smartly resolving local path installs to package names.
  • pytron frontend install [package]: Install npm packages for the frontend (auto-detects directory).
  • pytron run [--dev]: Run the application.
  • pytron show: List installed Python packages and versions.
  • pytron package: Build standalone executable.

Happy Coding with Pytron!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytron_kit-0.3.14.tar.gz (18.0 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pytron_kit-0.3.14-py3-none-win_amd64.whl (20.5 MB view details)

Uploaded Python 3Windows x86-64

pytron_kit-0.3.14-py3-none-manylinux_2_31_x86_64.whl (23.0 MB view details)

Uploaded Python 3manylinux: glibc 2.31+ x86-64

pytron_kit-0.3.14-py3-none-macosx_11_0_universal2.whl (20.5 MB view details)

Uploaded Python 3macOS 11.0+ universal2 (ARM64, x86-64)

File details

Details for the file pytron_kit-0.3.14.tar.gz.

File metadata

  • Download URL: pytron_kit-0.3.14.tar.gz
  • Upload date:
  • Size: 18.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pytron_kit-0.3.14.tar.gz
Algorithm Hash digest
SHA256 78e489b3aefea14159f93590732948f3d236e59c08a1c1da6e9838201e68c8e3
MD5 2b6308b697ea9ba220139a1107a831ce
BLAKE2b-256 71577f7dcfe7d8495ce6d1201558bc8322cda0020f88d37206f475a1c7b8782c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytron_kit-0.3.14.tar.gz:

Publisher: publish.yml on Ghua8088/pytron-kit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytron_kit-0.3.14-py3-none-win_amd64.whl.

File metadata

  • Download URL: pytron_kit-0.3.14-py3-none-win_amd64.whl
  • Upload date:
  • Size: 20.5 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pytron_kit-0.3.14-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 8801145a7434c35a365b29a6c88dec84720e5d1501139a68795751ebb399e6dd
MD5 28027112d7f8bd6862f6ec87ed626935
BLAKE2b-256 b17aadff19acb55404c9e4f3fdc5d73ec96794b08799083d85f220dade3ef7f7

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytron_kit-0.3.14-py3-none-win_amd64.whl:

Publisher: publish.yml on Ghua8088/pytron-kit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytron_kit-0.3.14-py3-none-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for pytron_kit-0.3.14-py3-none-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 74ee4f710fc10d5228d8737fdd9cd88afc4f75fca78173bdd6e659da37691a7c
MD5 93a42a088efab9d6792242293add97f9
BLAKE2b-256 4a487e4ec76fc8a2243d4a663b8123eade34d28237959a1c1d941d5a06d1c1c7

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytron_kit-0.3.14-py3-none-manylinux_2_31_x86_64.whl:

Publisher: publish.yml on Ghua8088/pytron-kit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytron_kit-0.3.14-py3-none-macosx_11_0_universal2.whl.

File metadata

File hashes

Hashes for pytron_kit-0.3.14-py3-none-macosx_11_0_universal2.whl
Algorithm Hash digest
SHA256 c560588435da462da02a2c0e63a1f09c160c8693567353aa225b4894ba7486e4
MD5 d78a628ca50fc6df534a8ae1e54cbf62
BLAKE2b-256 bb524d546554579e133879d7e0addfe2bf9ee441489a839ea0d39e953261160d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytron_kit-0.3.14-py3-none-macosx_11_0_universal2.whl:

Publisher: publish.yml on Ghua8088/pytron-kit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page