Redux-inspired UI framework for discord.py
Project description
Build predictable, state-driven interfaces with discord.py.
Design complex interactive systems with centralized state, composable UI patterns, and a clear data flow.
Why CascadeUI
Interactive Discord UIs become difficult to manage as they grow. State is scattered across callbacks, views become tightly coupled, and behavior becomes harder to reason about.
CascadeUI introduces structure:
- Centralized state instead of scattered variables
- Predictable updates through dispatched actions
- Clear separation between logic and presentation
- Reusable UI patterns instead of one-off implementations
- Built-in solutions for persistence, navigation, and state history
This approach scales from simple panels to full application-style interfaces.
Architecture
CascadeUI follows a unidirectional data flow model:
User interaction -> dispatch(action)
-> middleware
-> reducer (state update)
-> subscribers notified
-> views re-render
All state lives in a single store. Actions describe what happened. Reducers define how state changes. Views subscribe to relevant state and update automatically.
When to Use
CascadeUI is designed for building complex interfaces that go beyond simple interactions.
A powerful, fully featured UI library should be leveraged when your app requires:
- Shared state across multiple views
- Real data and message persistence
- Maintainable complex interaction logic
- Message lifecycle and ownership control
- Consistent UI composition
- Cross-view reactivity
- Multi-step flows and validation
It may be unnecessary for small or simple interfaces.
Features
For full details, see the official documentation.
State and Data Flow
- Centralized store with dispatch and reducer cycle
- Custom reducers via
@cascade_reducerdecorator with automatic deep copy - Action batching for grouped, atomic updates
- Computed state and derived values
- Selector-based subscriptions for targeted re-renders
- Cross-view reactivity: dispatch from any view, all subscribers update instantly
- Middleware pipeline for logging, persistence, and transformation
- Event hooks for lifecycle observation and side effects
Views and Interaction Patterns
- Layout-based V2 system for structured interfaces
- Full support for traditional discord.py Views (V1)
- Pre-built patterns: tabs, wizards, forms, pagination
- Navigation stack with push, pop, and replace
- Session limiting per user, guild, or globally with replace or reject policies
- Multi-user access control via
allowed_userswith participant-aware session limiting - Interaction ownership control (owner-only by default)
- Auto-defer for slow callbacks and interaction serialization for rapid input
- Theming with per-view overrides and V2 accent colors
Components and Composition
- Stateful buttons, selects, and modals with state integration
- V2 layout helpers:
card(),key_value(),alert(),action_section(), and more - Built-in form system with validation and per-field error handling
- Component wrappers: loading states, confirmation dialogs, cooldowns
Persistence and Infrastructure
- Persistent views that survive bot restarts with automatic message re-attachment
- State persistence backends: JSON, SQLite, Redis
- Undo and redo via snapshot-based state history
- Scoped state isolation (user, guild, global)
- Developer tools for live state inspection and debugging
Showcase
Dashboard Pattern
Structured, multi-section interfaces with tab-based navigation and composable layouts.
Navigation and Flow
Navigate between views without sending new messages. Maintain context across layered interfaces.
State History (Undo/Redo)
Snapshot-based state history per session with built-in undo and redo support.
Cross-View Reactivity
Dispatch actions from any view and update all subscribers instantly across the interface.
Lifecycle Control
Control active sessions per user, guild, or globally with automatic cleanup and replacement policies.
class DashboardView(TabLayoutView):
session_limit = 1 # Only one open at a time
session_scope = "user_guild" # Per user per guild
session_policy = "replace" # Exit the old one, open the new one
Persistence and Continuity
Persist views and state across restarts with automatic restoration.
# Enable persistence once in your bot's setup_hook:
async def setup_hook(self):
await setup_persistence(bot=self, backend=SQLiteBackend("cascadeui.db"))
Dynamic Pagination
Generate paginated interfaces from raw data with built-in navigation and formatting helpers.
from cascadeui import PaginatedLayoutView
def format_page(items):
lines = [f"**{item['name']}** | {item['rarity']} | {item['value']}g" for item in items]
return [Container(
TextDisplay("## Inventory"),
Separator(),
TextDisplay("\n".join(lines)),
accent_colour=discord.Color.blue(),
)]
view = await PaginatedLayoutView.from_data(
items=all_items,
per_page=4,
formatter=format_page,
context=ctx,
)
await view.send()
Forms and Validation
Define structured input flows with automatic validation and per-field error handling.
from cascadeui import FormLayoutView, choices, card, key_value, divider
class RegistrationForm(FormLayoutView):
session_limit = 1
def __init__(self, *args, **kwargs):
fields = [
{
"id": "role",
"label": "Role",
"type": "select",
"required": True,
"options": [
{"label": "Developer", "value": "developer"},
{"label": "Designer", "value": "designer"},
{"label": "Manager", "value": "manager"},
],
"validators": [choices(["developer", "designer", "manager"])],
},
{
"id": "terms",
"label": "Accept Terms of Service",
"type": "boolean",
"required": True,
},
]
super().__init__(
*args,
title="Registration",
fields=fields,
on_submit=self.handle_submit,
**kwargs,
)
def _rebuild_display(self):
"""Override display with V2 helpers for a richer presentation."""
v = self.values
action_rows = [c for c in self.children if isinstance(c, ActionRow)]
self.clear_items()
self.add_item(card(
"## Registration Form",
key_value({"Role": v.get("role", "-").title() if v.get("role") else "-"}),
divider(),
TextDisplay(f"Terms: {'Accepted' if v.get('terms') else 'Pending'}"),
))
for row in action_rows:
self.add_item(row)
Developer Tools
Live state inspection and debugging with a tabbed inspector view. Add one line to your bot.
from cascadeui.devtools import DevToolsCog
# In your bot's setup_hook:
await bot.add_cog(DevToolsCog(bot))
V1 Components
CascadeUI supports traditional discord.py Views and embeds.
Use V1 when you need:
- Embed-specific features such as fields or timestamps
- Simpler layouts without containers
All core features such as navigation, persistence, and undo/redo are supported.
Examples
The documentation includes full implementations demonstrating practical usage:
- Dashboards and control panels
- Settings systems
- Pagination
- Forms and wizards
- Persistent views
- Ticket systems
- Multi-user games
Getting Started
pip install pycascadeui
Optional dependencies:
pip install pycascadeui[sqlite]
pip install pycascadeui[redis]
Requirements:
- Python 3.10+
- discord.py 2.7+
Documentation
Support
- Discord: https://discord.com/invite/9Xj68BpKRb
- Issues: https://github.com/HollowTheSilver/CascadeUI/issues
Development
git clone https://github.com/HollowTheSilver/CascadeUI.git
cd CascadeUI
pip install -e ".[dev]"
pytest tests/ -v
black cascadeui/
isort cascadeui/
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pycascadeui-2.1.0.tar.gz.
File metadata
- Download URL: pycascadeui-2.1.0.tar.gz
- Upload date:
- Size: 112.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
75952334dbb9af30cf9065ddb73be5507f7f7f7da56491d4394f55006daef381
|
|
| MD5 |
6f8eadb1f2404c08296da99457758d40
|
|
| BLAKE2b-256 |
3af12b91aaca5bce7b75cf47f445f34b2476ba7f452320380a45dcd2e094f50c
|
Provenance
The following attestation bundles were made for pycascadeui-2.1.0.tar.gz:
Publisher:
publish.yml on HollowTheSilver/CascadeUI
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pycascadeui-2.1.0.tar.gz -
Subject digest:
75952334dbb9af30cf9065ddb73be5507f7f7f7da56491d4394f55006daef381 - Sigstore transparency entry: 1238643313
- Sigstore integration time:
-
Permalink:
HollowTheSilver/CascadeUI@947039f5d7c3f44dd02dfa78b4bdf95d2ed6ede2 -
Branch / Tag:
refs/tags/v2.1.0 - Owner: https://github.com/HollowTheSilver
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@947039f5d7c3f44dd02dfa78b4bdf95d2ed6ede2 -
Trigger Event:
release
-
Statement type:
File details
Details for the file pycascadeui-2.1.0-py3-none-any.whl.
File metadata
- Download URL: pycascadeui-2.1.0-py3-none-any.whl
- Upload date:
- Size: 97.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2325365823c8b198e8c96ae61791574c22c9d040f294178c95b9c8ebc9583fb5
|
|
| MD5 |
17f2218ac526fbd589d655235cc56d48
|
|
| BLAKE2b-256 |
739370b6ab197411e7783ef69b85b915cf6558e53efc5003164a4289187fd2fe
|
Provenance
The following attestation bundles were made for pycascadeui-2.1.0-py3-none-any.whl:
Publisher:
publish.yml on HollowTheSilver/CascadeUI
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pycascadeui-2.1.0-py3-none-any.whl -
Subject digest:
2325365823c8b198e8c96ae61791574c22c9d040f294178c95b9c8ebc9583fb5 - Sigstore transparency entry: 1238643322
- Sigstore integration time:
-
Permalink:
HollowTheSilver/CascadeUI@947039f5d7c3f44dd02dfa78b4bdf95d2ed6ede2 -
Branch / Tag:
refs/tags/v2.1.0 - Owner: https://github.com/HollowTheSilver
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@947039f5d7c3f44dd02dfa78b4bdf95d2ed6ede2 -
Trigger Event:
release
-
Statement type: