API Reference
Complete API documentation for djust's Python classes, decorators, and configuration.
Core Classes
LiveView
Base class for reactive server-side views
fromdjustimport LiveView
| Attribute | Type | Description |
|---|---|---|
template_name |
str | Path to template file |
use_actors |
bool | Enable Tokio actor-based state |
temporary_assigns |
dict | Assigns to clear after render |
Methods: [List]
Component
Stateless presentational component
fromdjustimport Component
Methods: [List]
LiveComponent
Stateful component with lifecycle and parent-child communication
fromdjustimport LiveComponent
Methods: [List]
Decorators
@event / @event_handler
Mark method as event handler with auto parameter introspection
@event
defincrement(self):
self.count += 1
@event_handler(description="Search products", coerce_types=True)
defsearch(self, query: str = "", **kwargs):
self.results = Product.objects.filter(name__icontains=query)
@state
Declare reactive state properties with default values
classMyView(LiveView):
count = state(default=0)
message = state(default="Hello")
@computed
Define computed properties derived from state
@computed
deftotal(self):
return self.subtotal + self.tax
@debounce
Debounce event handler calls on client side
@debounce(wait=0.3, max_wait=2.0)
defsearch(self, query: str = "", **kwargs):
pass
@throttle
Throttle event handler calls on client side
@throttle(interval=0.1, leading=True, trailing=True)
defon_scroll(self, scroll_y: int = 0, **kwargs):
pass
@optimistic
Apply optimistic updates before server validation
@optimistic
deftoggle_like(self, post_id: int = 0, **kwargs):
pass
@cache
Cache handler responses client-side
@cache(ttl=60, key_params=["query"])
defsearch(self, query: str = "", **kwargs):
pass
Configuration
# settings.py
LIVEVIEW_CONFIG = {
# ... see table below
}
| Key | Type | Default | Description |
|---|---|---|---|
use_websocket |
bool | True |
Use WebSocket or HTTP polling |
debug_vdom |
bool | False |
Enable VDOM patching debug logs |
debug_components |
bool | False |
Enable component lifecycle debug logs |
hot_reload |
bool | True |
Enable hot reload (requires DEBUG=True) |
jit_serialization |
bool | True |
Enable JIT auto-serialization |
jit_cache_backend |
str | filesystem |
JIT cache backend |
serialization_max_depth |
int | 3 |
Max nesting depth for models |
css_framework |
str | bootstrap5 |
CSS framework (bootstrap5, tailwind, None) |
render_labels |
bool | True |
Render field labels |
render_help_text |
bool | True |
Render help text |
auto_validate_on_change |
bool | True |
Validate fields on change |
Programmatic Configuration
fromdjust.configimport config
# Get
framework = config.get('css_framework')
field_class = config.get('bootstrap5.field_class')
# Set
config.set('css_framework', 'tailwind')
# Framework class
cls = config.get_framework_class('field_class')
Testing Utilities
LiveViewTestClient
Test LiveViews without browser/WebSocket
fromdjust.testingimport LiveViewTestClient
SnapshotTestMixin
Mixin for snapshot testing
fromdjust.testingimport SnapshotTestMixin
@performance_test
Assert performance thresholds in tests
fromdjust.testingimport performance_test
CLI Commands
| Command | Description |
|---|---|
djust health |
Health check |
djust stats |
Session statistics |
djust profile myapp.views.MyView |
Profile a view |
djust analyze myapp.views.MyView |
Analyze a view |
djust clear --sessions --vdom --jit |
Clear caches |
Imports Reference
# Core
fromdjustimport LiveView, Component, LiveComponent
# Decorators
fromdjustimport event, event_handler, state, computed, reactive
fromdjustimport debounce, throttle, optimistic, cache, client_state
# Forms
fromdjust.formsimport FormMixin
# Testing
fromdjust.testingimport LiveViewTestClient, SnapshotTestMixin, performance_test
# Configuration
fromdjust.configimport config, get_config
# Utilities
fromdjustimport cleanup_expired_sessions, get_session_stats