Installation
Requirements
Chanx has the following core dependencies:
Python 3.11+
Pydantic 2.0+
Structlog
PyHumps (for camelCase conversion)
Typing Extensions
Framework-specific dependencies are installed automatically based on which extra you choose.
Installing Chanx
Basic Installation (Core Only)
pip install chanx
For Django Channels Projects
pip install "chanx[channels]"
This installs:
Django 5.0+
Django Channels 4.0+
Django REST Framework 3.0+
Channels Redis 4.0+
For FastAPI and Other ASGI Frameworks
pip install "chanx[fast_channels]"
This installs:
FastAPI 0.117+
fast-channels 1.0+
Install from Source
git clone https://github.com/huynguyengl99/chanx.git
cd chanx
pip install -e ".[channels]" # For Django
# or
pip install -e ".[fast_channels]" # For FastAPI
Framework Setup
Django Channels Setup
Add necessary apps to your
INSTALLED_APPS:
INSTALLED_APPS = [
# ...
'rest_framework',
'channels',
'chanx.channels',
# ...
]
Configure Chanx in your Django settings:
# settings.py
CHANX = {
'CAMELIZE': False, # Set to True for camelCase conversion
'SEND_COMPLETION': False, # Set to True for testing
'LOG_WEBSOCKET_MESSAGE': True,
# ...
}
FastAPI Setup
Create a base consumer class:
# base_consumer.py
from chanx.fast_channels.websocket import AsyncJsonWebsocketConsumer
class BaseConsumer(AsyncJsonWebsocketConsumer):
# Configure per your needs
send_completion = False
log_websocket_message = True
channel_layer_alias = "default"
Import and use in your consumers:
from chanx.core.decorators import ws_handler, channel
from .base_consumer import BaseConsumer
@channel(name="chat")
class ChatConsumer(BaseConsumer):
@ws_handler
async def handle_ping(self, message: PingMessage) -> PongMessage:
return PongMessage()
Configuration Options
camelCase Conversion
Chanx includes automatic camelCase conversion. Enable it in your configuration:
# Django settings.py
CHANX = {
'CAMELIZE': True,
# ...
}
# Or for other frameworks, in your base consumer
class BaseConsumer(AsyncJsonWebsocketConsumer):
camelize = True
Next Steps
Now that you have Chanx installed, proceed to:
Django Quick Start - Create your first Django WebSocket consumer
FastAPI Quick Start - Create your first FastAPI WebSocket consumer
Prerequisites - Start with the user guide prerequisites
Django Complete Example - See Django implementation examples
FastAPI Complete Example - See FastAPI implementation examples