API Reference
Complete API documentation for djust's Python classes, decorators, and configuration.
Core Classes
LiveView
Base class for reactive server-side views
from djust import 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
from djust import Component
Methods:[List]
LiveComponent
Stateful component with lifecycle and parent-child communication
from djust import LiveComponent
Methods:[List]
Decorators
@event_handler
Mark method as event handler with auto parameter introspection
@event_handler
def increment(self):
self.count += 1
@event_handler(description="Search products", coerce_types=True)
def search(self, query: str = "", **kwargs):
self.results = Product.objects.filter(name__icontains=query)
@state
Declare reactive state properties with default values
class MyView(LiveView):
count = state(default=0)
message = state(default="Hello")
@computed
Define computed properties derived from state
@computed
def total(self):
return self.subtotal + self.tax
@debounce
Debounce event handler calls on client side
@debounce(wait=0.3, max_wait=2.0)
def search(self, query: str = "", **kwargs):
pass
@throttle
Throttle event handler calls on client side
@throttle(interval=0.1, leading=True, trailing=True)
def on_scroll(self, scroll_y: int = 0, **kwargs):
pass
@optimistic
Apply optimistic updates before server validation
@optimistic
def toggle_like(self, post_id: int = 0, **kwargs):
pass
@cache
Cache handler responses client-side
@cache(ttl=60, key_params=["query"])
def search(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
from djust.config import 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
from djust.testing import LiveViewTestClient
SnapshotTestMixin
Mixin for snapshot testing
from djust.testing import SnapshotTestMixin
@performance_test
Assert performance thresholds in tests
from djust.testing import 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
from djust import LiveView, Component, LiveComponent
# Decorators
from djust import event_handler, state, computed, reactive
from djust import debounce, throttle, optimistic, cache, client_state
# Forms
from djust.forms import FormMixin
# Testing
from djust.testing import LiveViewTestClient, SnapshotTestMixin, performance_test
# Configuration
from djust.config import config, get_config
# Utilities
from djust import cleanup_expired_sessions, get_session_stats