Lightweight Django Channels layer backed by SQLite database
Project description
channels-lite
Django Channels layer backed by SQLite database.
Installation
Basic Installation (Django ORM Layer)
pip install channels-lite
This installs the Django ORM-based channel layer that works with your existing Django database.
High-Performance Installation (AIOSQLite Layer)
pip install channels-lite[aio]
This installs the aiosqlite-based layer with aiosqlite, aiosqlitepool, and msgspec for better performance through direct async SQLite access and MessagePack encoding.
Usage
Django ORM Layer
Configure in your Django settings:
CHANNEL_LAYERS = {
"default": {
"BACKEND": "channels_lite.layers.core.SQLiteChannelLayer",
"CONFIG": {
"database": "default", # Django database alias
"expiry": 60,
"capacity": 100,
},
},
}
AIOSQLite Layer (High Performance)
CHANNEL_LAYERS = {
"default": {
"BACKEND": "channels_lite.layers.aio.AIOSQLiteChannelLayer",
"CONFIG": {
"database": "default", # Django database alias
"expiry": 60,
"capacity": 100,
"pool_size": 10,
"polling_interval": 0.1,
},
},
}
Note: Both layers use the same database parameter (Django database alias).
Configuring SQLite Performance Settings
The AIO layer respects Django's database init_command option. You can customize SQLite PRAGMA settings:
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": BASE_DIR / "db.sqlite3",
"OPTIONS": {
# Custom SQLite settings for AIO layer
"init_command": (
"PRAGMA journal_mode=WAL; "
"PRAGMA synchronous=NORMAL; "
"PRAGMA cache_size=10000; "
"PRAGMA temp_store=MEMORY;"
),
},
}
}
If no init_command is provided, the AIO layer uses optimized defaults:
PRAGMA journal_mode=WAL- Write-Ahead Logging for better concurrencyPRAGMA synchronous=NORMAL- Balanced durability/performancePRAGMA cache_size=10000- Larger cache for better performancePRAGMA temp_store=MEMORY- Store temp tables in memoryPRAGMA mmap_size=268435456- 256MB memory-mapped I/OPRAGMA page_size=4096- Optimal page sizePRAGMA busy_timeout=5000- 5 second timeout for locks
Features
- Two implementation options: Django ORM (easy setup) or aiosqlite (high performance)
- Process-local channel support: Unique channel names per process
- Group messaging: Send messages to multiple channels at once
- Message expiry: Automatic cleanup of expired messages
- Connection pooling: (aiosqlite layer) Efficient connection management
- MessagePack encoding: (aiosqlite layer) Fast binary serialization
TODO
High Priority (Robustness)
- Replace bare
except:clauses with specific exception handling (ChannelEmpty,OperationalError, etc.) - Replace print statements with proper logging (use
loggingmodule) - Add retry logic for database OperationalError (lock timeouts)
- Implement receive cancellation handling to prevent message loss
- Add buffer size limits to prevent unbounded memory growth
- Implement periodic VACUUM for database maintenance (reclaim space from deleted messages)
Documentation Needed
- Document SQLite WAL mode requirement for better concurrency
- Users must configure:
PRAGMA journal_mode=WAL - Recommended settings:
PRAGMA synchronous=NORMAL,PRAGMA busy_timeout=5000
- Users must configure:
- Document Django database configuration requirements
- Add usage examples and setup guide
- Document limitations vs Redis layer
Future Enhancements
- Create advanced layer using
aiosqlite+aiosqlitepoolfor better async support ✅- Direct connection pooling ✅
- Better concurrent write handling ✅
- More control over SQLite pragmas ✅
- Consider adding encryption support for sensitive messages
- Add health check endpoint for monitoring
- Add metrics/instrumentation for observability
Performance Optimizations
- Profile and optimize hot paths (send/receive loops)
- Consider batch operations for group_send
- Evaluate index optimization for Event and GroupMembership tables
- Benchmark against Redis layer for common workloads
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_lite-0.2.0.tar.gz.
File metadata
- Download URL: channels_lite-0.2.0.tar.gz
- Upload date:
- Size: 11.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5fabbef62b8809c57f17c899ae73651fbcb8db67b1fdd32ae1423ac3f4c6e00b
|
|
| MD5 |
00015ce46a56d8ad325e90514a78d67c
|
|
| BLAKE2b-256 |
2eb1d8d4319fb3e53aac3b4f464c30dfcb55f5fc44eba5b828531359bd1df717
|
Provenance
The following attestation bundles were made for channels_lite-0.2.0.tar.gz:
Publisher:
publish.yml on Tobi-De/channels-lite
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
channels_lite-0.2.0.tar.gz -
Subject digest:
5fabbef62b8809c57f17c899ae73651fbcb8db67b1fdd32ae1423ac3f4c6e00b - Sigstore transparency entry: 798292027
- Sigstore integration time:
-
Permalink:
Tobi-De/channels-lite@5120c959ed15b1941c4e6391e054069f90fb40c0 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/Tobi-De
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5120c959ed15b1941c4e6391e054069f90fb40c0 -
Trigger Event:
push
-
Statement type:
File details
Details for the file channels_lite-0.2.0-py3-none-any.whl.
File metadata
- Download URL: channels_lite-0.2.0-py3-none-any.whl
- Upload date:
- Size: 15.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6247dbed599784160f5f010c92471bfb6ff38ef8bd7e66553f1a9af7ccfa3eca
|
|
| MD5 |
1a7e2d87bf58cdad0647f2f4f377815f
|
|
| BLAKE2b-256 |
fe119738ebcc28c386d1e357cab232af699b79535edbe3bcfd4e8e8d766d5670
|
Provenance
The following attestation bundles were made for channels_lite-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on Tobi-De/channels-lite
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
channels_lite-0.2.0-py3-none-any.whl -
Subject digest:
6247dbed599784160f5f010c92471bfb6ff38ef8bd7e66553f1a9af7ccfa3eca - Sigstore transparency entry: 798292031
- Sigstore integration time:
-
Permalink:
Tobi-De/channels-lite@5120c959ed15b1941c4e6391e054069f90fb40c0 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/Tobi-De
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5120c959ed15b1941c4e6391e054069f90fb40c0 -
Trigger Event:
push
-
Statement type: