Core Concepts

Pytron-kit is a full-stack framework designed for cross-platform consistency and high-performance communication between backend and frontend layers.

1. Exposing Functions

Use the @app.expose decorator to make Python functions available to your frontend. Pytron-kit handles all data serialization and bridge communication automatically.

python
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. Type Safety

Import the client into your frontend to call exposed functions with full TypeScript support. Pytron-kit can generate .d.ts definitions directly from your Python type hints.

typescript
import pytron from 'pytron-client';

async function loadUser() {
    const user = await pytron.get_user(1);
    console.log(user.name); // Typed as string
}

3. Global Shortcuts

Register global keyboard shortcuts that function even when the application window is not focused.

python
# Register shortcut (Ctrl+Shift+SPACE)
app.shortcut("Ctrl+Shift+SPACE", lambda: app.toggle_visibility())

4. System Integration

Deeply integrate with the host operating system using built-in native APIs.

  • Taskbar Progress: Display progress directly in the OS taskbar.
  • Binary Streaming: Efficiently transfer raw bytes for high-frequency data needs.
  • Native Dialogs: Access native system pickers for files and directories.

5. Rendering Engines

Choose the rendering engine that best fits your distribution requirements:

  • Native Webview: Minimal distribution size (~5MB) using OS-native engines like WebView2 or WebKit.
  • Bundled Engine: Switch to a full Chrome Engine for total rendering consistency and proprietary media support.

Diagnostic Tool

If you encounter environment issues, run pytron doctor in your terminal. It verifies all required dependencies and assists in resolving configuration problems.