litestar-realtime

Implement WebSockets, Server-Sent Events, and pub/sub for Litestar applications.

13|Updated Apr 15, 2026
One-click install
npx skills add https://github.com/litestar-org/litestar-skills --skill litestar-realtime
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: litestar-realtime
Source: https://github.com/litestar-org/litestar-skills/tree/main/plugins/litestar/skills/litestar-realtime
Command: npx skills add https://github.com/litestar-org/litestar-skills --skill litestar-realtime

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Building realtime features like WebSockets, Server-Sent Events, and cross-service event fan-out in Litestar requires handling authentication, backend selection, typed event contracts, and cross-process publishing logic from scratch, leading to inconsistent implementations and avoidable bugs. This Skill provides opinionated, production-ready patterns for every layer of the Litestar realtime stack, eliminating boilerplate and ensuring consistency with Litestar best practices.

Core Features & Use Cases

  • WebSocket & SSE Handler Patterns: Pre-built templates for connection lifecycle management, multi-tenant authentication guards, and request-scoped dependency injection for realtime endpoints.
  • Channels Plugin Configuration: Ready-to-use setup for all supported backends (in-memory, Redis, PostgreSQL LISTEN/NOTIFY, SQLSpec) selected based on your existing stack dependencies to avoid unnecessary infrastructure.
  • Typed Event Contracts: Canonical RealtimeEvent envelope, scope-based access control tables, and channel naming factories for consistent, type-safe pub/sub messaging across services.
  • Cross-Process Publishing: Patterns for broadcasting events from SAQ workers, CLI scripts, and database observers to connected realtime clients, with graceful handling of uninitialized channel backends.
  • Use Case Example: Build a workspace event stream that authenticates users via JWT query parameters, restricts access to workspace members, and broadcasts ETL job status updates from background workers to all connected clients in real time.

Quick Start

Use the litestar-realtime skill to implement an authenticated WebSocket endpoint that streams workspace-specific events to authorized users with typed payloads and proper disconnect handling.

Frequently Asked Questions about litestar-realtime

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add authenticated WebSockets to a Litestar application?

You can add authenticated WebSockets to Litestar by using pre-built connection lifecycle patterns with multi-tenant authentication guards and request-scoped dependency injection for realtime endpoints. This provides typed payloads and proper disconnect handling without boilerplate.

What is the best way to broadcast events from background workers to WebSocket clients in Litestar?

Broadcasting events from background workers to WebSocket clients in Litestar is handled through cross-process pub/sub patterns. You can publish from SAQ workers or CLI scripts to connected clients using a canonical RealtimeEvent envelope with graceful handling of uninitialized backends.

Does the Litestar channels plugin support Redis and PostgreSQL backends?

Litestar channels support Redis, PostgreSQL LISTEN/NOTIFY, SQLSpec, and in-memory backends. Backend selection is configured based on your existing stack dependencies to avoid requiring unnecessary infrastructure for realtime pub/sub fan-out.

How do I enforce multi-tenant access control over Server-Sent Events in Litestar?

Multi-tenant access control for Server-Sent Events in Litestar is enforced via scope-based access control tables and channel naming factories. Typed event contracts ensure workspace members receive only authorized workspace-specific event streams.

Can I use JWT query parameters to authenticate Litestar WebSocket connections?

JWT query parameter authentication for Litestar WebSockets is supported via multi-tenant authentication guards. This allows you to restrict access to workspace members and stream workspace-specific events to authorized users over realtime connections.

What happens if I publish to a Litestar channel backend that is not initialized?

Publishing to an uninitialized Litestar channel backend triggers graceful handling logic. This ensures cross-process publishing from background workers or CLI scripts fails safely without crashing when the realtime pub/sub backend is not yet configured.