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://node00.wsocket.online", "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)
Push Notifications
from wsocket_io import PushClient
push = PushClient('https://your-server.com', 'your-api-key', 'your-app-id')
# Register device
push.register_fcm('device-token', 'user-123')
# Send to member
push.send_to_member('user-123', {'title': 'Hello', 'body': 'World'})
# Broadcast
push.broadcast({'title': 'News', 'body': 'Breaking news!'})
# Channel targeting
push.add_channel('subscription-id', 'alerts')
push.remove_channel('subscription-id', 'alerts')
# VAPID key
vapid_key = push.get_vapid_key()
# List subscriptions
subs = push.list_subscriptions('user-123')
# Delete subscription
push.delete_subscription('subscription-id')
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.2.0.tar.gz
(11.5 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.2.0.tar.gz.
File metadata
- Download URL: wsocket_io-0.2.0.tar.gz
- Upload date:
- Size: 11.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c5548f8b6db292cf8d252ee40c245515fd34782d1598d5085abfd7854f0e403a
|
|
| MD5 |
0f9ea13dc4d38403ce287ecc3261a3f9
|
|
| BLAKE2b-256 |
4ee8e810ed440e3b3f37eccc5c627c1e60c4b869c2da06bee5c46ce78d021c45
|
File details
Details for the file wsocket_io-0.2.0-py3-none-any.whl.
File metadata
- Download URL: wsocket_io-0.2.0-py3-none-any.whl
- Upload date:
- Size: 9.0 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 |
f39a0ba0a0e254059966d2c39fd2fc308f8ece64a771e3b4c29e0658015d47b0
|
|
| MD5 |
4db399adf7f04e415b1faebb45deb384
|
|
| BLAKE2b-256 |
a5ba47be45a7fdf032e4c597f236e421767e2c538269a9c986ff28a5f5cfa01a
|