Skip to main content

fastx-channels

WebSocket channel abstraction for FastX -- pub/sub rooms, presence tracking, and Redis backend support.

Installation

pip install fastx-channels

# With Redis support
pip install fastx-channels[redis]

Quick Start

from starlette.websockets import WebSocket
from fastx_channels import Channel, ChannelManager, InMemoryBackend, Message

# Create a manager with an in-memory backend
backend = InMemoryBackend()
manager = ChannelManager(backend)

# In a WebSocket endpoint
async def websocket_endpoint(websocket: WebSocket):
    await websocket.accept()
    channel = manager.get_or_create("chat:lobby")

    # Subscribe the connection
    await channel.subscribe(websocket)

    try:
        while True:
            data = await websocket.receive_json()
            msg = Message(channel="chat:lobby", event="message", data=data)
            await channel.publish(msg)
    finally:
        await channel.unsubscribe(websocket)

Presence Tracking

from fastx_channels import PresenceService, InMemoryPresenceBackend

presence = PresenceService(InMemoryPresenceBackend())

await presence.join("chat:lobby", user_id="user_1", metadata={"name": "Alice"})
members = await presence.get_members("chat:lobby")
online = await presence.is_online("chat:lobby", "user_1")
await presence.leave("chat:lobby", "user_1")

Redis Backend (multi-process)

from redis.asyncio import Redis
from fastx_channels import RedisBackend, ChannelManager

redis_client = Redis.from_url("redis://localhost:6379")
backend = RedisBackend(redis_client)
manager = ChannelManager(backend)

License

MIT

Metadata

Release files for fastx-channels 1.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fastx-channels 1.7.0
File Size Uploaded
fastx_channels-1.7.0.tar.gz 7.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fastx-channels 1.7.0
File Interpreter ABI Platform
fastx_channels-1.7.0-py3-none-any.whl Python 3 none any Details

Total release size: 18.4 kB

Release files / fastx_channels-1.7.0.tar.gz

Download URL fastx_channels-1.7.0.tar.gz
Size 7.9 kB
Tags Source
SHA-256 checksum
How to use checksums
01a1732852aa9532a7324080bfc39744f24a859a2eb8adc19d59026c34091213
BLAKE2b-256 checksum
How to use checksums
6f3bf5d99e3fd3f871a10737262c9bdf5e99820bdcdd7df169cc51fe368c8d10
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Release files / fastx_channels-1.7.0-py3-none-any.whl

Download URL fastx_channels-1.7.0-py3-none-any.whl
Size 10.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2c67a5c81adfaa18642e3c34716213e4ecf7e5072c10cea363934b1635c3e1f5
BLAKE2b-256 checksum
How to use checksums
2d675df2c3b8d0a75b538aceecc274fc3846da078250d753e49c632766181349
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

1.7.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page