Sqlite3 Based Channel Layer
Project description
channels-sqlite is a Django app providing a channels layer backed by SQLite. It uses a dedicated SQLite3 database for asynchronous message handling, making it lightweight and easy to set up without Redis or other external services.
1. Add the app to INSTALLED_APPS
INSTALLED_APPS = [
# other apps
"channels",
"channels_sqlite",
]
2. Configure databases
You need two SQLite databases: one for your main Django data (default), and one dedicated to Channels (channels).
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": BASE_DIR / "db.sqlite3",
},
"channels": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": BASE_DIR / "channels.sqlite3",
"init_command": "PRAGMA journal_mode=WAL;",
"transaction_mode": "IMMEDIATE",
"OPTIONS": {
"timeout": 20,
"init_command": """
PRAGMA journal_mode=WAL;
PRAGMA synchronous=NORMAL;
PRAGMA busy_timeout=20000;
PRAGMA cache_size=-64000;
PRAGMA temp_store=MEMORY;
PRAGMA mmap_size=134217728;
""",
},
},
}
3. Configure the channel layer
CHANNEL_LAYERS = {
"default": {
"BACKEND": "channels_sqlite.layers.SqliteChannelLayer",
"CONFIG": {
"database": "channels", # must match database alias
"polling_interval": 0.05, # Poll every 50ms
"message_retention": 86400, # Keep messages for 1 day
"capacity": 100, # Max messages per consumer queue
"expiry": 30, # Message TTL in seconds
"trim_batch_size": 100, # Cleanup batch size
"auto_trim": True, # Auto cleanup old messages
},
},
}
4. Add database router
DATABASE_ROUTERS = [
"channels_sqlite.db_routers.ChannelsRouter",
]
This ensures that migrations for channels_sqlite go into the dedicated channels database.
5. Apply migrations
Run migrations for both databases:
# Default Django models
python manage.py migrate
# Channels-specific tables
python manage.py migrate --database=channels
6. Start the development server
python manage.py runserver
Your channel layer is now configured. Django Channels will handle WebSocket and background task messages asynchronously using the lightweight SQLite channels database.
Example Project
This repository also contains an example/ Django project that demonstrates how to use channels-sqlite in practice.
To run the example:
cd example
uv sync
python manage.py migrate
python manage.py migrate --database=channels
python manage.py runserver
Then open http://127.0.0.1:8000/chat in your browser to test it.
channels-sqlite provides a simple, dependency-free way to get started with Django Channels, perfect for development and lightweight deployments.
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 channels_sqlite-0.1.tar.gz.
File metadata
- Download URL: channels_sqlite-0.1.tar.gz
- Upload date:
- Size: 14.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e82889f9cd300707adf1db094b9e3f54c829e52bb1752da38e9d00942035346a
|
|
| MD5 |
acd04dabe0c13191bd6f4df3fca9e2fe
|
|
| BLAKE2b-256 |
3b3afd4dd6fca5e9d2e6a189fc62cdaf78b293e8b7fc791bc33b1f9b3190b48e
|
File details
Details for the file channels_sqlite-0.1-py3-none-any.whl.
File metadata
- Download URL: channels_sqlite-0.1-py3-none-any.whl
- Upload date:
- Size: 14.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
11681d5f24cc0dbfdf27a273f6b9099204cd39c36742a8c050a938b44d66f479
|
|
| MD5 |
39b88aae737c9e712f76737bceb4d3a8
|
|
| BLAKE2b-256 |
d2b27f99bbe2155cfe7a4fc710707aaf62d8578ceca92d6878d8753738bf89cd
|