Mesop Documentation

repository·main·Indexed 24 days ago

https://github.com/mesop-dev/mesop

Mesop is an open-source Python-based UI framework designed for the rapid development of web applications, demos, and internal tools. It enables developers to build custom UIs using idiomatic Python without requiring JavaScript, CSS, or HTML. The framework includes features for programmatic navigation, component focusing, and state session caching with backends supporting memory, file, SQL, and Firestore.

Tokens
41.4K
Snippets
122
Records
303
Agent score
87%

What's inside Mesop

  1. Overview of Mesop Web Components

    main

    Mesop supports custom web components, an experimental feature (released under labs) that allows you to use web standards (JavaScript and CSS) to define custom HTML elements. This enables you to extend Mesop's capabilities beyond standard Python components.

    Key Use Cases:

    • Custom JavaScript: Execute custom JS with simple bi-directional communication between the browser and the Python server.
    • JavaScript Libraries: Wrap existing JS libraries into a web component to use them within Mesop.
    • Rich Client-side Interactivity: Implement stateful client-side interactions that do not require a network roundtrip to the server.
  2. Overview of Mesop

    main

    Mesop is a Python-based UI framework designed for rapid web application development, specifically targeting engineers without extensive frontend experience. It allows developers to build web UIs using idiomatic Python code while leveraging the mature Angular web framework and Angular Material components under the hood.

    Key features include:

    • A fast build-edit-refresh loop via hot reload.
    • A flexible and composable components API.
    • Easy deployment using standard HTTP technologies like Server-Sent Events (SSE).
  3. Understand Mesop's JavaScript and Content Security Policy

    main

    Mesop uses Angular's built-in security protections and enforces a strict Content Security Policy (CSP).

    • Mesop APIs prevent arbitrary JavaScript execution in the main context (e.g., the markdown component sanitizes content to remove active HTML/JavaScript).
    • The default CSP prevents arbitrary JavaScript execution unless it complies with Angular's Trusted Types policies.
  4. Apply styles to components using the Mesop Style API

    main
    Mesop provides a Python API that wraps the browser's native CSS style API. You can use these helpers to apply inline styles to components, allowing for fine-grained control over layout and appearance.
  5. Compare Mesop component extensibility with Streamlit and Gradio

    main

    For building custom interfaces:

    • Streamlit: Uses custom components rendered in iframes (often React-based) for isolation.
    • Gradio: Offers pre-built ML components and allows custom components via Python and JavaScript (Svelte).
    • Mesop: Uses general-purpose UI components that can be composed into higher-level components (like chat). It supports creating custom web components based on open web standards (e.g., Lit), which are rendered in the same frame as the rest of the app for high flexibility.