wSocket Realtime Pub/Sub SDK for Python
Project description
wSocket Python SDK
Official Python SDK for wSocket — Realtime Pub/Sub over WebSockets.
Installation
pip install wsocket-io
Quick Start
import asyncio
from wsocket import create_client
async def main():
client = create_client("wss://your-server.com", "your-api-key")
await client.connect()
chat = client.channel("chat:general")
@chat.on_message
def handle(data, meta):
print(f"[{meta.channel}] {data}")
chat.subscribe()
chat.publish({"text": "Hello from Python!"})
await asyncio.sleep(5)
await client.disconnect()
asyncio.run(main())
Features
- Pub/Sub — Subscribe and publish to channels in real-time
- Presence — Track who is online in a channel
- History — Retrieve past messages
- Connection Recovery — Automatic reconnection with message replay
- Async/Await — Built on
asyncioandwebsockets
Presence
chat = client.channel("chat:general")
@chat.presence.on_enter
def user_joined(member):
print(f"Joined: {member.client_id}")
@chat.presence.on_leave
def user_left(member):
print(f"Left: {member.client_id}")
chat.presence.enter({"name": "Alice"})
members = chat.presence.get()
History
@chat.on_history
def handle_history(result):
for msg in result.messages:
print(f"[{msg['timestamp']}] {msg['data']}")
chat.history(limit=50)
Requirements
- Python >= 3.9
websockets >= 12.0
Development
pip install -e ".[dev]"
pytest
License
MIT
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
wsocket_io-0.1.0.tar.gz
(10.7 kB
view details)
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 wsocket_io-0.1.0.tar.gz.
File metadata
- Download URL: wsocket_io-0.1.0.tar.gz
- Upload date:
- Size: 10.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4e07ce515b4f26c6f8654053be82fa73eb2ee21b32b3913dd66f19853cf4795c
|
|
| MD5 |
163dec1c06fe933b2476bf674c5e71eb
|
|
| BLAKE2b-256 |
0872673c55fb357e2a866cfda8c968588fdc11919cbc621d64cdb331fa49ffb8
|
File details
Details for the file wsocket_io-0.1.0-py3-none-any.whl.
File metadata
- Download URL: wsocket_io-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a365a78e3f968fc90521c67a397650c6a3c899705458289f776efc253c763edc
|
|
| MD5 |
7da3c964f794eb331f1372a658b90928
|
|
| BLAKE2b-256 |
a9443f393472886cb630bfef440926734ccdd230b87c8e10054f65143f60556a
|