Skip to main content

WebSocket channel abstraction for FastX — pub/sub rooms, presence tracking, Redis backend.

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastx_channels-1.7.0.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastx_channels-1.7.0-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file fastx_channels-1.7.0.tar.gz.

File metadata

  • Download URL: fastx_channels-1.7.0.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for fastx_channels-1.7.0.tar.gz
Algorithm Hash digest
SHA256 01a1732852aa9532a7324080bfc39744f24a859a2eb8adc19d59026c34091213
MD5 7eefaafb88dc667dfb9121cf79d62727
BLAKE2b-256 6f3bf5d99e3fd3f871a10737262c9bdf5e99820bdcdd7df169cc51fe368c8d10

See more details on using hashes here.

File details

Details for the file fastx_channels-1.7.0-py3-none-any.whl.

File metadata

  • Download URL: fastx_channels-1.7.0-py3-none-any.whl
  • Upload date:
  • Size: 10.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for fastx_channels-1.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2c67a5c81adfaa18642e3c34716213e4ecf7e5072c10cea363934b1635c3e1f5
MD5 4000d58c24618d9e8df1e0354faa179c
BLAKE2b-256 2d675df2c3b8d0a75b538aceecc274fc3846da078250d753e49c632766181349

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page