Blazing fast reactive server-side rendering for Django, powered by Rust
Project description
๐ djust
Blazing fast reactive server-side rendering for Django, powered by Rust
djust brings Phoenix LiveView-style reactive components to Django, with performance that feels native. Write server-side Python code with automatic, instant client updatesโno JavaScript bundling, no build step, no complexity.
๐ djust.org | ๐ Quick Start | ๐ฎ Playground
โจ Features
- โก 10-100x Faster - Rust-powered template engine and Virtual DOM diffing
- ๐ Reactive Components - Phoenix LiveView-style server-side reactivity
- ๐ Django Compatible - Works with existing Django templates and components
- ๐ฆ Zero Build Step - Just ~5KB of client JavaScript, no bundling needed
- ๐ WebSocket Updates - Real-time DOM patches over WebSocket (with HTTP fallback)
- ๐ฏ Minimal Client Code - Smart diffing sends only what changed
- ๐ Type Safe - Rust guarantees for core performance-critical code
- ๐ Developer Debug Panel - Interactive debugging with event history and VDOM inspection
๐ฏ Quick Example
from djust import LiveView
class CounterView(LiveView):
template_string = """
<div>
<h1>Count: {{ count }}</h1>
<button @click="increment">+</button>
<button @click="decrement">-</button>
</div>
"""
def mount(self, request, **kwargs):
self.count = 0
def increment(self):
self.count += 1 # Automatically updates client!
def decrement(self):
self.count -= 1
That's it! No JavaScript needed. State changes automatically trigger minimal DOM updates.
๐ Performance
Benchmarked on M1 MacBook Pro (2021):
| Operation | Django | djust | Speedup |
|---|---|---|---|
| Template Rendering (100 items) | 2.5 ms | 0.15 ms | 16.7x |
| Large List (10k items) | 450 ms | 12 ms | 37.5x |
| Virtual DOM Diff | N/A | 0.08 ms | Sub-ms |
| Round-trip Update | 50 ms | 5 ms | 10x |
Run benchmarks yourself:
cd benchmarks
python benchmark.py
๐ Installation
Prerequisites
- Python 3.8+
- Rust 1.70+ (for building from source)
- Django 3.2+
Install from PyPI (when published)
pip install djust
Build from Source
Using Make (Easiest - Recommended for Development)
# Clone the repository
git clone https://github.com/djust-org/djust.git
cd djust
# Install Rust (if needed)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# Install everything and build
make install
# Start the development server
make start
# See all available commands
make help
Common Make Commands:
make start- Start development server with hot reloadmake stop- Stop the development servermake status- Check if server is runningmake test- Run all testsmake clean- Clean build artifactsmake help- Show all available commands
Using uv (Fast)
# Clone the repository
git clone https://github.com/djust-org/djust.git
cd djust
# Install Rust (if needed)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# Install uv (if needed)
curl -LsSf https://astral.sh/uv/install.sh | sh
# Create virtual environment and install dependencies
uv venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Install maturin and build
uv pip install maturin
maturin develop --release
Using pip
# Clone the repository
git clone https://github.com/djust-org/djust.git
cd djust
# Install Rust (if needed)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install maturin
pip install maturin
# Build and install
maturin develop --release
# Or build wheel
maturin build --release
pip install target/wheels/djust-*.whl
๐ Documentation
Setup
- Add to
INSTALLED_APPS:
INSTALLED_APPS = [
# ...
'channels', # Required for WebSocket support
'djust',
# ...
]
- Configure ASGI application (
asgi.py):
import os
from django.core.asgi import get_asgi_application
from channels.routing import ProtocolTypeRouter, URLRouter
from channels.auth import AuthMiddlewareStack
from djust.websocket import LiveViewConsumer
from django.urls import path
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings')
application = ProtocolTypeRouter({
"http": get_asgi_application(),
"websocket": AuthMiddlewareStack(
URLRouter([
path('ws/live/', LiveViewConsumer.as_asgi()),
])
),
})
- Add to
settings.py:
ASGI_APPLICATION = 'myproject.asgi.application'
CHANNEL_LAYERS = {
'default': {
'BACKEND': 'channels.layers.InMemoryChannelLayer'
}
}
Creating LiveViews
Class-Based LiveView
from djust import LiveView
class TodoListView(LiveView):
template_name = 'todos.html' # Or use template_string
def mount(self, request, **kwargs):
"""Called when view is first loaded"""
self.todos = []
def add_todo(self, text):
"""Event handler - called from client"""
self.todos.append({'text': text, 'done': False})
def toggle_todo(self, index):
self.todos[index]['done'] = not self.todos[index]['done']
Function-Based LiveView
from djust import live_view
@live_view(template_name='counter.html')
def counter_view(request):
count = 0
def increment():
nonlocal count
count += 1
return locals() # Returns all local variables as context
Template Syntax
djust supports Django template syntax with event binding:
<!-- Variables -->
<h1>{{ title }}</h1>
<!-- Filters -->
<p>{{ text|upper }}</p>
<!-- Control flow -->
{% if show %}
<div>Visible</div>
{% endif %}
{% for item in items %}
<li>{{ item }}</li>
{% endfor %}
<!-- Event binding -->
<button @click="increment">Click me</button>
<input @input="on_search" type="text" />
<form @submit="submit_form">
<input name="email" />
<button type="submit">Submit</button>
</form>
Supported Events
@click- Click events@input- Input events (passesvalue)@change- Change events (passesvalue)@submit- Form submission (passes form data as dict)
Reusable Components
djust provides a powerful component system with automatic state management and stable component IDs.
Basic Component Example
from djust.components import AlertComponent
class MyView(LiveView):
def mount(self, request):
# Components get automatic IDs based on attribute names
self.alert_success = AlertComponent(
message="Operation successful!",
type="success",
dismissible=True
)
# component_id automatically becomes "alert_success"
Component ID Management
Components automatically receive a stable component_id based on their attribute name in your view. This eliminates manual ID management:
# When you write:
self.alert_success = AlertComponent(message="Success!")
# The framework automatically:
# 1. Sets component.component_id = "alert_success"
# 2. Persists this ID across renders and events
# 3. Uses it in HTML: data-component-id="alert_success"
# 4. Routes events back to the correct component
Why it works:
- The attribute name (
alert_success) is already unique within your view - It's stable across re-renders and WebSocket reconnections
- Event handlers can reference components by their attribute names
- No manual ID strings to keep in sync
Event Routing Example:
class MyView(LiveView):
def mount(self, request):
self.alert_warning = AlertComponent(
message="Warning message",
dismissible=True
)
def dismiss(self, component_id: str = None):
"""Handle dismissal - automatically routes to correct component"""
if component_id and hasattr(self, component_id):
component = getattr(self, component_id)
if hasattr(component, 'dismiss'):
component.dismiss() # component_id="alert_warning"
When the dismiss button is clicked, the client sends component_id="alert_warning", and the handler uses getattr(self, "alert_warning") to find the component.
Creating Custom Components
from djust import Component, register_component
@register_component('my-button')
class Button(Component):
template = '<button @click="on_click">{{ label }}</button>'
def __init__(self, label="Click"):
super().__init__()
self.label = label
self.clicks = 0
def on_click(self):
self.clicks += 1
print(f"Clicked {self.clicks} times!")
Decorators
from djust import LiveView, event_handler, reactive
class MyView(LiveView):
@event_handler
def handle_click(self):
"""Marks method as event handler"""
pass
@reactive
def count(self):
"""Reactive property - auto-triggers updates"""
return self._count
@count.setter
def count(self, value):
self._count = value
Configuration
Configure djust in your Django settings.py:
LIVEVIEW_CONFIG = {
# Transport mode
'use_websocket': True, # Set to False for HTTP-only mode (no WebSocket dependency)
# Debug settings
'debug_vdom': False, # Enable detailed VDOM patch logging (for troubleshooting)
# CSS Framework
'css_framework': 'bootstrap5', # Options: 'bootstrap5', 'tailwind', None
}
Common Configuration Options:
| Option | Default | Description |
|---|---|---|
use_websocket |
True |
Use WebSocket transport (requires Django Channels) |
debug_vdom |
False |
Enable detailed VDOM debugging logs |
css_framework |
'bootstrap5' |
CSS framework for components |
Debug Mode:
When troubleshooting VDOM issues, enable debug logging:
# In settings.py
LIVEVIEW_CONFIG = {
'debug_vdom': True,
}
# Or programmatically
from djust.config import config
config.set('debug_vdom', True)
This will log:
- Server-side: Patch generation details (stderr)
- Client-side: Patch application and DOM traversal (browser console)
State Management
djust provides Python-only state management decorators that eliminate the need for manual JavaScript.
๐ Quick Start (5 minutes)
Build a debounced search in 8 lines of Python (no JavaScript):
from djust import LiveView
from djust.decorators import debounce
class ProductSearchView(LiveView):
template_string = """
<input @input="search" placeholder="Search products..." />
<div>{% for p in results %}<div>{{ p.name }}</div>{% endfor %}</div>
"""
def mount(self, request):
self.results = []
@debounce(wait=0.5) # Wait 500ms after typing stops
def search(self, query: str = "", **kwargs):
self.results = Product.objects.filter(name__icontains=query)[:10]
That's it! Server only queries after you stop typing. Add @optimistic for instant UI updates, @cache(ttl=300) to cache responses for 5 minutes.
๐ Full Quick Start Guide (5 min)
Key Features
- โ Zero JavaScript Required - Common patterns work without writing any JS
- โ 87% Code Reduction - Decorators replace hundreds of lines of manual JavaScript
- โ Smallest Bundle - 7.1 KB client.js (vs Phoenix ~30KB, Livewire ~50KB)
- โ Competitive DX - Matches Phoenix LiveView and Laravel Livewire developer experience
Available Decorators
| Decorator | Use When | Example |
|---|---|---|
@debounce(wait) |
User is typing | Search, autosave |
@throttle(interval) |
Rapid events | Scroll, resize |
@optimistic |
Instant feedback | Counter, toggle |
@cache(ttl, key_params) |
Repeated queries | Autocomplete |
@client_state(keys) |
Multi-component | Dashboard filters |
DraftModeMixin |
Auto-save forms | Contact form |
Quick Decision Matrix:
- Typing in input? โ
@debounce(0.5) - Scrolling/resizing? โ
@throttle(0.1) - Need instant UI update? โ
@optimistic - Same query multiple times? โ
@cache(ttl) - Multiple components? โ
@client_state([keys]) - Auto-save forms? โ
DraftModeMixin
Learn More
- ๐ Quick Start (5 min) - Get productive fast
- ๐ Full Tutorial (20 min) - Step-by-step Product Search
- ๐ API Reference - Complete decorator docs + cheat sheet
- ๐ฏ Examples - Copy-paste ready code
- ๐ Migration Guide - Convert JavaScript to Python
- โ๏ธ Framework Comparison - vs Phoenix LiveView & Laravel Livewire
Developer Tooling
Debug Panel
Interactive debugging tool for LiveView development (DEBUG mode only):
# In settings.py
DEBUG = True # Debug panel automatically enabled
Open: Press Ctrl+Shift+D (Windows/Linux) or Cmd+Shift+D (Mac), or click the ๐ floating button
Features:
- ๐ Event Handlers - Discover all handlers with parameters, types, and descriptions
- ๐ Event History - Real-time log with timing metrics (e.g.,
search โข 45.2ms) - โก VDOM Patches - Monitor DOM updates with sub-millisecond precision
- ๐ฌ Variables - Inspect current view state
Learn More:
- ๐ Debug Panel Guide - Complete user guide
- ๐ Event Handler Best Practices - Patterns and conventions
Event Handlers
Always use @event_handler decorator for auto-discovery and validation:
from djust.decorators import event_handler
@event_handler()
def search(self, value: str = "", **kwargs):
"""Search handler - description shown in debug panel"""
self.search_query = value
Parameter Convention: Use value for form inputs (@input, @change events):
# โ
Correct - matches what form events send
@event_handler()
def search(self, value: str = "", **kwargs):
self.search_query = value
# โ Wrong - won't receive input value
@event_handler()
def search(self, query: str = "", **kwargs):
self.search_query = query # Always "" (default)
๐๏ธ Architecture
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Browser โ
โ โโโ Client.js (5KB) - Event & DOM patches โ
โ โโโ WebSocket Connection โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ๏ธ WebSocket (Binary/JSON)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Django + Channels (Python) โ
โ โโโ LiveView Classes โ
โ โโโ Event Handlers โ
โ โโโ State Management โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ๏ธ Python/Rust FFI (PyO3)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Rust Core (Native Speed) โ
โ โโโ Template Engine (<1ms) โ
โ โโโ Virtual DOM Diffing (<100ฮผs) โ
โ โโโ HTML Parser โ
โ โโโ Binary Serialization (MessagePack) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐จ Examples
See the examples/demo_project directory for complete working examples:
- Counter - Simple reactive counter
- Todo List - CRUD operations with lists
- Chat - Real-time messaging
Run the demo:
cd examples/demo_project
pip install -r requirements.txt
python manage.py migrate
python manage.py runserver
Visit http://localhost:8000
๐ง Development
Project Structure
djust/
โโโ crates/
โ โโโ djust_core/ # Core types & utilities
โ โโโ djust_templates/ # Template engine
โ โโโ djust_vdom/ # Virtual DOM & diffing
โ โโโ djust_live/ # Main PyO3 bindings
โโโ python/
โ โโโ djust/ # Python package
โ โโโ live_view.py # LiveView base class
โ โโโ component.py # Component system
โ โโโ websocket.py # WebSocket consumer
โ โโโ static/
โ โโโ client.js # Client runtime
โโโ examples/ # Example projects
โโโ benchmarks/ # Performance benchmarks
โโโ tests/ # Tests
Running Tests
# Rust tests
cargo test
# Python tests
pytest
# Integration tests
cd examples/demo_project
python manage.py test
Building Documentation
cargo doc --open
๐ฐ Supporting djust
djust is open source (MIT licensed) and free forever. If you're using djust in production or want to support development:
- โญ Star this repo - Help others discover djust
- ๐ GitHub Sponsors - Monthly support from $5/month
Your support helps us maintain and improve djust for everyone!
๐ค Contributing
Contributions welcome! Please read CONTRIBUTING.md first.
Areas we'd love help with:
- Additional Django template filters/tags
- More example applications
- Performance optimizations
- Documentation improvements
- Browser compatibility testing
๐ Roadmap
- Template inheritance (
{% extends %}) - More Django template filters
- File upload handling
- Server-sent events (SSE) fallback
- React/Vue component compatibility
- TypeScript definitions
- Redis-backed session storage
- Horizontal scaling support
๐ Security
- CSRF protection via Django middleware
- XSS protection via automatic template escaping
- WebSocket authentication via Django sessions
- Rate limiting support
Report security issues to: security@djust.org
๐ License
MIT License - see LICENSE file for details.
๐ Acknowledgments
- Inspired by Phoenix LiveView
- Built with PyO3 for Python/Rust interop
- Uses html5ever for HTML parsing
- Powered by the amazing Rust and Django communities
๐ฌ Community & Support
- ๐ djust.org - Official website
- ๐ Quick Start - Get started in minutes
- ๐ฎ Playground - Try djust in your browser
- ๐ Issues - Bug reports & feature requests
- ๐ง Email: support@djust.org
djust.org โ Made with โค๏ธ by the djust community
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 Distributions
Built Distributions
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 djust-0.1.0-cp310-cp310-win_amd64.whl.
File metadata
- Download URL: djust-0.1.0-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 2.8 MB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7385b0ffb9eb1566ad548003295e36f600e8326e233eaef7af921efc65584eac
|
|
| MD5 |
ee0b7813bc15790d0d3a846e92d96f5a
|
|
| BLAKE2b-256 |
449385cb9d0a437a9adc929b2a1e704dd554bf8eb74f14e0bac0f6cbe08512eb
|
Provenance
The following attestation bundles were made for djust-0.1.0-cp310-cp310-win_amd64.whl:
Publisher:
publish.yml on djust-org/djust
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
djust-0.1.0-cp310-cp310-win_amd64.whl -
Subject digest:
7385b0ffb9eb1566ad548003295e36f600e8326e233eaef7af921efc65584eac - Sigstore transparency entry: 832230512
- Sigstore integration time:
-
Permalink:
djust-org/djust@b7ed32155dc6fdcb1605ae7b37a345e9c5c56f66 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/djust-org
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b7ed32155dc6fdcb1605ae7b37a345e9c5c56f66 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file djust-0.1.0-cp310-cp310-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: djust-0.1.0-cp310-cp310-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 2.8 MB
- Tags: CPython 3.10, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
386a01120084e30a6adcc971688474bf7c364b88846ed0cde527398d14e0c856
|
|
| MD5 |
a395622b116829734dac81a14b6ed7bc
|
|
| BLAKE2b-256 |
68fe97fb22491c5ba7cdc906b320a8006bc2a239b8b0d69b2d050a0facb48a7b
|
Provenance
The following attestation bundles were made for djust-0.1.0-cp310-cp310-manylinux_2_34_x86_64.whl:
Publisher:
publish.yml on djust-org/djust
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
djust-0.1.0-cp310-cp310-manylinux_2_34_x86_64.whl -
Subject digest:
386a01120084e30a6adcc971688474bf7c364b88846ed0cde527398d14e0c856 - Sigstore transparency entry: 832230479
- Sigstore integration time:
-
Permalink:
djust-org/djust@b7ed32155dc6fdcb1605ae7b37a345e9c5c56f66 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/djust-org
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b7ed32155dc6fdcb1605ae7b37a345e9c5c56f66 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file djust-0.1.0-cp310-cp310-macosx_11_0_arm64.whl.
File metadata
- Download URL: djust-0.1.0-cp310-cp310-macosx_11_0_arm64.whl
- Upload date:
- Size: 2.7 MB
- Tags: CPython 3.10, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
19f6fc65dea2c9cc9b7d013f9d6945d8c6f13288569b3f62f0cf282fad62ac2f
|
|
| MD5 |
c2e5970dcde22f66abfb94082ed0e389
|
|
| BLAKE2b-256 |
01b3924b129040cb3009b48f8812c7666deed9b14ebd7ce03cf34544029ec4f7
|
Provenance
The following attestation bundles were made for djust-0.1.0-cp310-cp310-macosx_11_0_arm64.whl:
Publisher:
publish.yml on djust-org/djust
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
djust-0.1.0-cp310-cp310-macosx_11_0_arm64.whl -
Subject digest:
19f6fc65dea2c9cc9b7d013f9d6945d8c6f13288569b3f62f0cf282fad62ac2f - Sigstore transparency entry: 832230498
- Sigstore integration time:
-
Permalink:
djust-org/djust@b7ed32155dc6fdcb1605ae7b37a345e9c5c56f66 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/djust-org
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b7ed32155dc6fdcb1605ae7b37a345e9c5c56f66 -
Trigger Event:
workflow_dispatch
-
Statement type: