Skip to main content

lexigram-ui

HTMX/htpy component library for Lexigram web applications.


Overview

lexigram-ui provides server-rendered UI primitives — components, layouts, HTMX helpers, and rendering utilities — built on htpy for plain Python templates. It ships with atoms (Button, TextInput, Badge), molecules (Card, Modal, Tabs), organisms (Form, SlideOver), and layouts, all integrated via UIModule for DI wiring and config-driven defaults.

The library ships with ShadCN-compatible CSS variable design tokens in oklch color space, a polymorphic asChild pattern for slot-based composition, and a component CLI (lexigram-ui add) for scaffolding components into your project.


Install

uv add lexigram-ui

Quick Start

from lexigram.di.module import Module, module
from lexigram.ui.module import UIModule
from lexigram.ui.config import UIConfig
from lexigram.ui.atoms import Button
from lexigram.ui.core.base import Component, el, render_to_string


@module(imports=[UIModule.configure(UIConfig(default_theme="default"))])
class AppModule(Module):
    pass


class SavePanel(Component):
    def render(self) -> object:
        return el(
            "section",
            el("h2", "Profile"),
            Button("Save", hx_post="/profile/save"),
            class_="bg-card text-card-foreground p-6 rounded-lg shadow-sm",
        )


html = render_to_string(SavePanel())

Configuration

Zero-config usage: Call UIModule.configure() with no arguments to use all defaults.

flowchart LR
    subgraph Input["Configuration Sources"]
        Y["application.yaml<br/>ui: section"]
        E["Environment vars<br/>LEX_UI__*"]
        P["Python API<br/>UIConfig(...)"]
    end
    UC["UIConfig<br/>merged + validated"]
    UM["UIModule.configure"]
    App["Application"]

    Y --> UC
    E --> UC
    P --> UC
    UC --> UM
    UM --> App

Option 1 — YAML file

# application.yaml
ui:
  default_theme: "default"
  auto_escape: true
  htmx_version: "2.0.4"
  debug_components: false
  theme: light
  enable_sse: false
  enable_realtime: false

Option 2 — Profiles + Environment Variables (recommended)

export LEX_UI__DEFAULT_THEME=default
export LEX_UI__DEBUG_COMPONENTS=false
export LEX_UI__THEME=dark

Option 3 — Python

from lexigram.ui.module import UIModule
from lexigram.ui.config import UIConfig

UIModule.configure(
    UIConfig(
        default_theme="default",
        theme="dark",
        enable_sse=True,
    )
)

Config reference

Field Default Env var Description
default_theme "default" LEX_UI__DEFAULT_THEME Default UI theme (default, dark, light, system)
auto_escape true LEX_UI__AUTO_ESCAPE HTML-escape user-supplied strings by default
htmx_version "2.0.4" LEX_UI__HTMX_VERSION HTMX asset version referenced in layout helpers
debug_components false LEX_UI__DEBUG_COMPONENTS Render data-component debug attributes (dev only)
theme "light" LEX_UI__THEME Active theme (light, dark, system)
enable_sse false LEX_UI__ENABLE_SSE Enable server-sent event support
enable_realtime false LEX_UI__ENABLE_REALTIME Enable realtime-oriented UI features

Module Factory Methods

Method Description
UIModule.configure(config, **kwargs) Register UIProvider with explicit UIConfig values
UIModule.stub() Default no-op module for tests

Key Features

  • Core rendering primitivesComponent, Element, RawHTML, el, raw, render_to_string
  • Polymorphic asChild pattern — slot-based composition via as_child parameter on Component, Button, Link, Card
  • ShadCN design tokens — CSS variable system in oklch color space: SHADCN_DEFAULT_COLORS, SHADCN_DARK_COLORS, shadcn_css() generator, SEMANTIC_CLASSES
  • Theme systemshadcn_css() generates complete :root / .dark CSS blocks with overridable primary, background, foreground, radius, status colors
  • Component CLIlexigram-ui add <component> scaffolds components into your project (12 components in registry: button, card, modal, input, select, tabs, toast, tooltip, skeleton, form, badge, pagination)
  • HTMX helpershx_get, hx_post, hx_target, hx_swap, and higher-level helpers
  • Server-Sent EventsSSEMessage and SSEStream for realtime UI
  • Component library — atoms, molecules, organisms, and layouts organized by usage layer
  • Context and swap zonesUIContext, Zone, Zones, SwapMode
  • Error and response helpersvalidation_error, render_validation_errors, htmx_error_response
  • AccessibilityAriaAttrs, SkipLink, announce, ARIA role helpers
  • PerformanceRenderCache, ResponseOptimizer, MetricsCollector
  • CSP requirementsUI_CSP_REQUIREMENTS for Content Security Policy configuration

Testing

async with Application.boot(modules=[UIModule.stub()]) as app:
    # your test code
    ...

Key Source Files

File What it contains
src/lexigram/ui/module.py UIModule.configure(), .stub()
src/lexigram/ui/config.py UIConfig, DebounceConfig, HTMLDocumentConfig, BaseLayoutConfig, HeadConfig, FooterConfig, ToastConfig
src/lexigram/ui/core/base.py Component, Element, el, render_to_string
src/lexigram/ui/core/slot.py Slot — pass-through renderer for asChild pattern
src/lexigram/ui/protocols.py RenderableProtocol
src/lexigram/ui/styles/design_tokens.py SHADCN_DEFAULT_COLORS, SHADCN_DARK_COLORS, render_all_tokens()
src/lexigram/ui/styles/theme.py shadcn_css() — complete CSS variable generation
src/lexigram/ui/styles/tokens.py Semantic class maps (button, alert, toast, icon colors)
src/lexigram/ui/atoms/__init__.py Button, TextInput, Badge, Icon
src/lexigram/ui/molecules/__init__.py Card, Modal, Tabs, Toast
src/lexigram/ui/organisms/__init__.py Form, SlideOver, Chart
src/lexigram/ui/htmx/attrs.py hx_get, hx_post, hx_target, hx_swap
src/lexigram/ui/htmx/sse.py SSEMessage, SSEStream
src/lexigram/ui/cli/registry.py COMPONENT_REGISTRY, ComponentEntry — 12 registerable components
src/lexigram/ui/cli/add.py lexigram-ui add CLI command (typer)
src/lexigram/ui/constants.py UITheme, Breakpoint, UI_CSP_REQUIREMENTS

Download files

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

Source Distribution

lexigram_ui-0.1.5001.tar.gz (255.8 kB view details)

Uploaded Source

Built Distribution

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

lexigram_ui-0.1.5001-py3-none-any.whl (252.8 kB view details)

Uploaded Python 3

File details

Details for the file lexigram_ui-0.1.5001.tar.gz.

File metadata

  • Download URL: lexigram_ui-0.1.5001.tar.gz
  • Upload date:
  • Size: 255.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.14

File hashes

Hashes for lexigram_ui-0.1.5001.tar.gz
Algorithm Hash digest
SHA256 7fe10ab53caa1dac5ce9c96bbed718a9ff47f631c0dd6f4e823fe483e380de7e
MD5 a9e6f33da20be0faff89ac7d92e59ea2
BLAKE2b-256 72c67be105e0009207bb28475d3212ac04acd69eb406a0227d7f43486eaa8505

See more details on using hashes here.

File details

Details for the file lexigram_ui-0.1.5001-py3-none-any.whl.

File metadata

File hashes

Hashes for lexigram_ui-0.1.5001-py3-none-any.whl
Algorithm Hash digest
SHA256 a5d9c141fdb7529662d02fd059db032ac69ae0fd5e8a09b7b6c1c04dbfbe8c59
MD5 1b06c1213007e34091095e54968e5127
BLAKE2b-256 5a56656f4983d44f294b7b8534f47250a6fb305ee4e7e469f49d871486c6b5d3

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.5008

1 file

0.1.5003

2 files

This release

0.1.5001 This release

2 files

0.1.3009

1 file

0.1.3008

2 files

0.1.3007

1 file

0.1.3006

1 file

0.1.3005

1 file

0.1.4

2 files

0.1.2

1 file

0.1.1

1 file

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page