Pyloid Docs
GithubLanguage
  • 💎What is Pyloid?
  • Getting Started
    • Prerequisites
    • Create Pyloid App
  • Core Concepts
    • Thread Safety
  • API
    • Python (Backend)
      • Pyloid
      • BrowserWindow
      • Monitor
      • TrayEvent
      • Utility Functions
      • RPC
      • Store
    • Javascript (Frontend)
      • Event
      • BaseAPI
      • RPC
  • Guides
    • Load Webview
    • Serve Frontend
    • Calling Python from JS
    • Calling JS from Python
    • Keyboard Shotcuts
    • Notification
    • Tray
    • Timer
    • File Watcher
    • Clipboard
    • Window Position
    • Devtools
    • Window Drag Region
    • Window Radius And Transparent
    • Autostart
    • Production Utils
    • Desktop Monitor
    • File Dialog
    • Splash Screen
Powered by GitBook
On this page
  • Basic Usage
  • Function Details
  • Parameters
  • Returns
  • How It Works

Was this helpful?

Edit on GitHub
  1. Guides

Serve Frontend

Pyloid provides functionality to easily serve web-based UIs. Using the pyloid_serve function from the pyloid.serve module, you can serve static files from a local HTTP server. The server uses dynamic port allocation by default, automatically finding an available port on your system.

Basic Usage

from pyloid import Pyloid
from pyloid.serve import pyloid_serve

app = Pyloid("Pyloid-App")

url = pyloid_serve("dist-front")  # Serve static files from dist-front folder

window = app.create_window("Pyloid-App")
window.load_url(url)
window.show_and_focus()

Function Details

pyloid_serve(directory: str, port: Optional[int] = None) -> str

Parameters

  • directory (str): Path to the static file directory to serve

  • port (int, optional): Server port (default: None - will use dynamic port allocation to automatically find an available port)

Returns

  • str: URL of the started server (e.g. "http://127.0.0.1:65421")

How It Works

The pyloid_serve function internally uses Python's http.server module to run a lightweight HTTP server in a separate thread. When no port is specified, it utilizes dynamic port allocation to find an available port on your system, ensuring that the server can start without port conflicts. This server runs as a daemon thread, so it terminates when the main application exits.

PreviousLoad WebviewNextCalling Python from JS

Last updated 29 days ago

Was this helpful?