channels-extensions 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ __pycache__/
2
+ .coverage
3
+ dist/
4
+ *.sqlite3
@@ -0,0 +1,43 @@
1
+ repos:
2
+ - repo: https://github.com/pre-commit/pre-commit-hooks
3
+ rev: v6.0.0
4
+ hooks:
5
+ - id: check-added-large-files
6
+ - id: check-ast
7
+ - id: check-builtin-literals
8
+ - id: check-case-conflict
9
+ - id: check-executables-have-shebangs
10
+ - id: check-illegal-windows-names
11
+ - id: check-json
12
+ exclude: ".vscode/.*"
13
+ - id: check-merge-conflict
14
+ - id: check-shebang-scripts-are-executable
15
+ - id: check-symlinks
16
+ - id: check-toml
17
+ - id: check-vcs-permalinks
18
+ - id: check-xml
19
+ - id: check-yaml
20
+ - id: debug-statements
21
+ - id: destroyed-symlinks
22
+ - id: detect-private-key
23
+ - id: end-of-file-fixer
24
+ - id: fix-byte-order-marker
25
+ - id: forbid-submodules
26
+ - id: name-tests-test
27
+ args:
28
+ - --pytest-test-first
29
+ - id: no-commit-to-branch
30
+ - id: trailing-whitespace
31
+
32
+ - repo: https://github.com/astral-sh/ruff-pre-commit
33
+ rev: v0.16.0
34
+ hooks:
35
+ - id: ruff
36
+ args: [--fix]
37
+ - id: ruff-format
38
+
39
+ - repo: https://github.com/adamchainz/django-upgrade
40
+ rev: "1.31.1"
41
+ hooks:
42
+ - id: django-upgrade
43
+ args: [--target-version, "5.2"]
@@ -0,0 +1,22 @@
1
+ {
2
+ // Use IntelliSense to learn about possible attributes.
3
+ // Hover to view descriptions of existing attributes.
4
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
+ "version": "0.2.0",
6
+ "configurations": [
7
+
8
+ {
9
+ "name": "Python Debugger: Django",
10
+ "type": "debugpy",
11
+ "purpose": ["debug-test"],
12
+ "request": "launch",
13
+ "args": [
14
+ "runserver"
15
+ ],
16
+ "django": true,
17
+ "autoStartBrowser": false,
18
+ "program": "${workspaceFolder}/manage.py",
19
+ "justMyCode": true
20
+ }
21
+ ]
22
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "python.testing.pytestArgs": [
3
+ "tests"
4
+ ],
5
+ "python.testing.unittestEnabled": false,
6
+ "python.testing.pytestEnabled": true
7
+ }
@@ -0,0 +1,22 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
6
+
7
+ This project adheres to both [Semantic Versioning](https://semver.org/spec/v2.0.0.html) and [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/).
8
+
9
+ ## [UNRELEASED]
10
+
11
+ ## [0.0.1] - 2026-07-28
12
+
13
+ ### Added
14
+
15
+ - This CHANGELOG file.
16
+ - `DummyChannelLayer` empty channel layer implementation
17
+ - `get_channel_layer` shortcut which raises an error for missing aliases
18
+ - `CurrentSiteMiddleware` that mimics django's own `CurrentSiteMiddleware`
19
+ - `JsonWebsocketConsumer` and `AsyncJsonWebsocketConsumer` for `orjson`-backed WebSocket JSON handling
20
+
21
+ [unreleased]: https://github.com/hartungstenio/channels-extensions/compare/0.0.1...HEAD
22
+ [0.0.1]: https://github.com/hartungstenio/channels-extensions/releases/tag/0.0.1
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026-present Christian Hartung <6785871+hartungstenio@users.noreply.github.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,93 @@
1
+ Metadata-Version: 2.4
2
+ Name: channels-extensions
3
+ Version: 0.0.1
4
+ Summary: Some extensions for Django Channels.
5
+ Project-URL: Documentation, https://github.com/hartungstenio/channels-extensions#readme
6
+ Project-URL: Issues, https://github.com/hartungstenio/channels-extensions/issues
7
+ Project-URL: Source, https://github.com/hartungstenio/channels-extensions
8
+ Author-email: Christian Hartung <6785871+hartungstenio@users.noreply.github.com>
9
+ License-Expression: MIT
10
+ License-File: LICENSE.txt
11
+ Keywords: django
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Framework :: Django :: 5.2
14
+ Classifier: Framework :: Django :: 6.0
15
+ Classifier: Programming Language :: Python
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Programming Language :: Python :: 3.14
20
+ Classifier: Programming Language :: Python :: Implementation :: CPython
21
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
22
+ Requires-Python: >=3.11
23
+ Requires-Dist: asgiref
24
+ Requires-Dist: asyncio-extensions
25
+ Requires-Dist: channels
26
+ Requires-Dist: django>=5.2
27
+ Requires-Dist: typing-extensions; python_version < '3.12'
28
+ Provides-Extra: orjson
29
+ Requires-Dist: django-orjson; extra == 'orjson'
30
+ Description-Content-Type: text/markdown
31
+
32
+ # channels-extensions
33
+
34
+ [![PyPI - Version](https://img.shields.io/pypi/v/channels-extensions.svg)](https://pypi.org/project/channels-extensions)
35
+ [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/channels-extensions.svg)](https://pypi.org/project/channels-extensions)
36
+
37
+ -----
38
+
39
+ ## Installation
40
+
41
+ ```console
42
+ pip install channels-extensions
43
+ ```
44
+
45
+ ## Usage
46
+
47
+ ### DummyChannelLayer
48
+ ```DummyChannelLayer``` is an noop (almost) implementation of `BaseChannelLayer`. Messages sent to it are never available, and `receive` never returns.
49
+
50
+ All methods work as checkpoints to the event loop, yielding control back to it at least once.
51
+
52
+ ```python
53
+ CHANNEL_LAYERS = {
54
+ "dummy": {
55
+ "BACKEND": "channels_extensions.layers.DummyChannelLayer",
56
+ }
57
+ }
58
+ ```
59
+
60
+ ### get_channel_layer
61
+ This is simply a version of channels `get_channel_layer`, but it raises an `ImproperlyConfigured` if the alias does not exist.
62
+
63
+ ### CurrentSiteMiddleware
64
+ A middleware that mimics django's `CurrentSiteMiddleware`. It adds a `site` key to the scope:
65
+ ```python
66
+ class EchoSiteConsumer(AsyncConsumer):
67
+ async def websocket_connect(self, event):
68
+ await self.send({
69
+ "type": "websocket.accept",
70
+ })
71
+
72
+ async def websocket_receive(self, event):
73
+ await self.send({
74
+ "type": "websocket.send",
75
+ "text": self.scope["site"],
76
+ })
77
+
78
+ application = ProtocolTypeRouter({
79
+ "websocket": AllowedHostsOriginValidator(
80
+ AuthMiddlewareStack(
81
+ CurrentSiteMiddleware(
82
+ URLRouter([
83
+ path("echo/", EchoSiteConsumer.as_asgi()),
84
+ ])
85
+ )
86
+ )
87
+ ),
88
+ })
89
+ ```
90
+
91
+ ## License
92
+
93
+ `channels-extensions` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.
@@ -0,0 +1,62 @@
1
+ # channels-extensions
2
+
3
+ [![PyPI - Version](https://img.shields.io/pypi/v/channels-extensions.svg)](https://pypi.org/project/channels-extensions)
4
+ [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/channels-extensions.svg)](https://pypi.org/project/channels-extensions)
5
+
6
+ -----
7
+
8
+ ## Installation
9
+
10
+ ```console
11
+ pip install channels-extensions
12
+ ```
13
+
14
+ ## Usage
15
+
16
+ ### DummyChannelLayer
17
+ ```DummyChannelLayer``` is an noop (almost) implementation of `BaseChannelLayer`. Messages sent to it are never available, and `receive` never returns.
18
+
19
+ All methods work as checkpoints to the event loop, yielding control back to it at least once.
20
+
21
+ ```python
22
+ CHANNEL_LAYERS = {
23
+ "dummy": {
24
+ "BACKEND": "channels_extensions.layers.DummyChannelLayer",
25
+ }
26
+ }
27
+ ```
28
+
29
+ ### get_channel_layer
30
+ This is simply a version of channels `get_channel_layer`, but it raises an `ImproperlyConfigured` if the alias does not exist.
31
+
32
+ ### CurrentSiteMiddleware
33
+ A middleware that mimics django's `CurrentSiteMiddleware`. It adds a `site` key to the scope:
34
+ ```python
35
+ class EchoSiteConsumer(AsyncConsumer):
36
+ async def websocket_connect(self, event):
37
+ await self.send({
38
+ "type": "websocket.accept",
39
+ })
40
+
41
+ async def websocket_receive(self, event):
42
+ await self.send({
43
+ "type": "websocket.send",
44
+ "text": self.scope["site"],
45
+ })
46
+
47
+ application = ProtocolTypeRouter({
48
+ "websocket": AllowedHostsOriginValidator(
49
+ AuthMiddlewareStack(
50
+ CurrentSiteMiddleware(
51
+ URLRouter([
52
+ path("echo/", EchoSiteConsumer.as_asgi()),
53
+ ])
54
+ )
55
+ )
56
+ ),
57
+ })
58
+ ```
59
+
60
+ ## License
61
+
62
+ `channels-extensions` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env python
2
+ """Django's command-line utility for administrative tasks."""
3
+
4
+ import os
5
+ import sys
6
+
7
+
8
+ def main():
9
+ """Run administrative tasks."""
10
+ os.environ.setdefault("DJANGO_SETTINGS_MODULE", "testproj.settings")
11
+ try:
12
+ from django.core.management import execute_from_command_line # noqa: PLC0415
13
+ except ImportError as exc:
14
+ msg = (
15
+ "Couldn't import Django. Are you sure it's installed and "
16
+ "available on your PYTHONPATH environment variable? Did you "
17
+ "forget to activate a virtual environment?"
18
+ )
19
+ raise ImportError(msg) from exc
20
+ execute_from_command_line(sys.argv)
21
+
22
+
23
+ if __name__ == "__main__":
24
+ main()
@@ -0,0 +1,159 @@
1
+ [project]
2
+ name = "channels-extensions"
3
+ description = "Some extensions for Django Channels."
4
+ readme = "README.md"
5
+ requires-python = ">=3.11"
6
+ license = "MIT"
7
+ license-files = ["LICENSE.txt"]
8
+ authors = [
9
+ { name = "Christian Hartung", email = "6785871+hartungstenio@users.noreply.github.com" },
10
+ ]
11
+ keywords = ["django"]
12
+ classifiers = [
13
+ "Development Status :: 4 - Beta",
14
+ "Framework :: Django :: 5.2",
15
+ "Framework :: Django :: 6.0",
16
+ "Programming Language :: Python",
17
+ "Programming Language :: Python :: 3.11",
18
+ "Programming Language :: Python :: 3.12",
19
+ "Programming Language :: Python :: 3.13",
20
+ "Programming Language :: Python :: 3.14",
21
+ "Programming Language :: Python :: Implementation :: CPython",
22
+ "Programming Language :: Python :: Implementation :: PyPy",
23
+ ]
24
+ dependencies = [
25
+ "asgiref",
26
+ "asyncio-extensions",
27
+ "channels",
28
+ "django>=5.2",
29
+ "typing-extensions; python_version < '3.12'",
30
+ ]
31
+ dynamic = ["version"]
32
+
33
+ [project.optional-dependencies]
34
+ orjson = ["django-orjson"]
35
+
36
+ [project.urls]
37
+ Documentation = "https://github.com/hartungstenio/channels-extensions#readme"
38
+ Issues = "https://github.com/hartungstenio/channels-extensions/issues"
39
+ Source = "https://github.com/hartungstenio/channels-extensions"
40
+
41
+ [dependency-groups]
42
+ dev = [
43
+ "coverage[toml]>=6.5",
44
+ "django-stubs>=5.2",
45
+ "faker",
46
+ "mypy",
47
+ "pre-commit",
48
+ "pytest",
49
+ "pytest-asyncio",
50
+ "pytest-django",
51
+ "types-channels",
52
+ ]
53
+
54
+ [build-system]
55
+ requires = ["hatch-vcs", "hatchling"]
56
+ build-backend = "hatchling.build"
57
+
58
+ [tool.coverage.run]
59
+ source_pkgs = ["channels_extensions", "tests"]
60
+ branch = true
61
+ parallel = true
62
+
63
+ [tool.coverage.paths]
64
+ channels_extensions = [
65
+ "src/channels_extensions",
66
+ "*/channels-extensions/src/channels_extensions"
67
+ ]
68
+ tests = ["tests", "*/channels-extensions/tests"]
69
+
70
+ [tool.coverage.report]
71
+ exclude_lines = [
72
+ "no cov",
73
+ "if __name__ == .__main__.:",
74
+ "if TYPE_CHECKING:",
75
+ ]
76
+
77
+ [tool.deptry]
78
+ known_first_party = ["channels_extensions"]
79
+
80
+ [tool.django-stubs]
81
+ django_settings_module = "testproj.settings"
82
+
83
+ [tool.hatch.build.targets.wheel]
84
+ sources = ["src"]
85
+
86
+ [tool.hatch.build.targets.sdist]
87
+ exclude = ["/.devcontainer", "/.github"]
88
+
89
+ [tool.hatch.version]
90
+ source = "vcs"
91
+
92
+ [tool.hatch.envs.default]
93
+ features = ["orjson"]
94
+ dependency-groups = ["dev"]
95
+
96
+ [tool.hatch.envs.hatch-test]
97
+ features = ["orjson"]
98
+ extra-dependencies = [
99
+ "faker",
100
+ "pytest-asyncio",
101
+ "pytest-django",
102
+ ]
103
+
104
+ [[tool.hatch.envs.hatch-test.matrix]]
105
+ python = ["3.11", "3.12", "3.13", "3.14"]
106
+
107
+ [[tool.hatch.envs.hatch-test.matrix]]
108
+ django = ["5.2"]
109
+ python = ["3.11", "3.12", "3.13", "3.14"]
110
+
111
+ [[tool.hatch.envs.hatch-test.matrix]]
112
+ django = ["6.0"]
113
+ python = ["3.12", "3.13", "3.14"]
114
+
115
+ [tool.hatch.envs.hatch-test.overrides]
116
+ matrix.django.dependencies = [
117
+ { value = "django>=5.2,<6.0", if = ["5.2"] },
118
+ { value = "django>=6.0,<6.1", if = ["6.0"] },
119
+ ]
120
+
121
+ [tool.hatch.envs.hatch-static-analysis]
122
+ skip-install = false
123
+ config-path = "ruff_defaults.toml"
124
+ dependencies = ["ruff==0.14.10"]
125
+
126
+ [tool.mypy]
127
+ plugins = ["mypy_django_plugin.main"]
128
+
129
+ [[tool.mypy.overrides]]
130
+ module = "channels_extensions.migrations.*"
131
+ ignore_errors = true
132
+
133
+ [[tool.mypy.overrides]]
134
+ module = "django.*"
135
+ ignore_missing_imports = true
136
+
137
+ [[tool.mypy.overrides]]
138
+ module = "pytest.*"
139
+ ignore_missing_imports = true
140
+
141
+ [tool.pytest]
142
+ pythonpath = [".", "src"]
143
+ DJANGO_SETTINGS_MODULE = "testproj.settings"
144
+ asyncio_default_fixture_loop_scope = "function"
145
+
146
+ [tool.ruff]
147
+ extend = "ruff_defaults.toml"
148
+
149
+ [tool.ruff.lint]
150
+ extend-select = ["DJ"]
151
+
152
+ [tool.ruff.lint.extend-per-file-ignores]
153
+ "*/migrations/*" = ["RUF012"]
154
+
155
+ [tool.ruff.lint.flake8-tidy-imports]
156
+ ban-relative-imports = "parents"
157
+
158
+ [tool.ruff.lint.flake8-tidy-imports.banned-api]
159
+ "asyncio.TaskGroup".msg = "Use asyncio_extensions.TaskGroup instead."