Registry / type-stubs / types-channels

types-channels

JSON →
library4.3.0.20260518pypypiunverified

types-channels is a stub package providing type hints for the `channels` library, which enables asynchronous communication for Django. It allows static type checkers like MyPy to understand the types used within `channels` code, improving code quality and maintainability. It is part of the `typeshed` project and is currently at version 4.3.0.20260408, with releases frequently updated to track upstream `channels` and `typeshed` changes.

pip install types-channels
INSTALL
IMPORT
SIG · TYPES-CHANNELS
T
types-channels
type-stubspythonv4.3.0.20260518
Install
3.7s avg
Import
670ms
Disk
70MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v4.3.0.20260518 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.940 runs
installs and imports cleanly · install 0.0s · import 0.717s · 70.8MB
glibc
py 3.103.940 runs
installs and imports cleanly · install 3.7s · import 0.622s · 71MB
70MB installed
● package 70MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ProtocolTypeRouter
from channels_stubs.routing import ProtocolTypeRouter
from channels_stubs.routing import ProtocolTypeRouter

To use `types-channels`, install it alongside the `channels` library and a type checker like MyPy (`pip install channels types-channels mypy`). Then, simply write your `channels` code with type annotations. MyPy will automatically pick up the stubs from `types-channels` when checking your code. For instance, save the example consumer above as `my_consumer.py` and run `mypy my_consumer.py` in your terminal. If correctly configured, MyPy should report no errors, validating your type hints based on the installed stubs.

import asyncio from channels.generic.websocket import AsyncWebsocketConsumer from typing import Dict, Any, Union # Example consumer, save as `my_consumer.py` class MyConsumer(AsyncWebsocketConsumer): async def connect(self) -> None: await self.accept() print("WebSocket connected!") async def disconnect(self, close_code: int) -> None: print(f"WebSocket disconnected with code: {close_code}") async def receive(self, text_data: Union[str, None] = None, bytes_data: Union[bytes, None] = None) -> None: if text_data: response: Dict[str, Any] = {"message": f"Received: {text_data}"} await self.send(text_data=str(response)) print("Received data.") async def main(): # This part is just to make the example runnable for demonstration of type hints. # In a real application, connect and disconnect would be called by the ASGI server. consumer = MyConsumer() await consumer.connect() # Simulate a received message for type checking await consumer.receive(text_data="Hello from client!") await consumer.disconnect(1000) if __name__ == '__main__': asyncio.run(main())
Debug
Known issues
gotcha`types-channels` provides only type stub files (`.pyi`) for static analysis by tools like MyPy. It does not contain any executable Python code for runtime and should never be imported directly.
fix
Always import symbols from the actual `channels` library (e.g., `from channels.routing import ProtocolTypeRouter`), not `types_channels`.
affects: All versions
gotchaStub package versions (like `types-channels`) are typically designed for specific versions of their corresponding runtime library (`channels`). Using significantly mismatched versions can lead to incorrect type checking results or MyPy errors.
fix
Ensure `types-channels` and `channels` are reasonably compatible. Check `typeshed` changelogs or `channels` release notes for guidance on compatibility if you encounter type errors. Consider pinning versions (e.g., `channels<5` for current stubs).
affects: All versions
gotchaFor MyPy to effectively use `types-channels`, ensure your MyPy configuration allows it to follow imports. Default settings usually work, but issues might arise with custom `mypy.ini` configurations.
fix
Verify MyPy's `follow_imports` setting. The default `normal` is usually sufficient. If MyPy reports 'Library 'channels' has no type information available', ensure `types-channels` is installed in the environment MyPy is checking.
affects: All versions
Upgrade
Version history
4.3.0.20260518latest on PyPI · released May 18, 2026
Audit
Dependencies
channelsrequiredProvides the actual runtime implementation that these stubs type-hint. You must install `channels` to use these type stubs effectively.
Agent activity
40 hits · last 30 days
node
38
OpenAI (training)
1
Resources
types-channels — pip install types-channels · libregistry