phxsocket
Synchronous phoenix websocket client using callbacks
Requirements
websockets
Usage
Import the package
import phxsocket
Create socket client
socket = phxsocket.Client("wss://target.url/channel/websocket", {"options": "something"})
Connect and join a channel
if socket.connect(): # blocking, raises exception on failure
channel = socket.channel("room:roomname", {"more options": "something else"})
resp = channel.join() # also blocking, raises exception on failure
Alternatively
def connect_to_channel(socket):
channel = socket.channel("room:roomname", {"more options": "something else"})
resp = channel.join()
socket.on_open = connect_to_channel
connection = socket.connect(blocking=False)
connection.wait() # blocking, raises exception on failure
Reconnect on disconnection
socket.on_close = lambda socket: socket.connect()
Subscribe to events
def do_something(payload):
thing = payload["thing"]
channel.on("eventname", do_something)
Push data to a channel
channel.push("eventname", {"some": "data"})
Push data and wait for a response
message = channel.push("eventname", {"some": "data"}, reply=True)
response = message.wait_for_response() # blocking
Push data and react to the response with a callback
def respond(payload):
print(payload)
channel.push("eventname", {"some": "data"}, respond)
Leave a channel
channel.leave()
Disconnect
socket.close()
Metadata
Release files for phxsocket 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| phxsocket-0.1.2.tar.gz | 4.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| phxsocket-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 22.0 kB
Release files / phxsocket-0.1.2.tar.gz
| Download URL | phxsocket-0.1.2.tar.gz |
|---|---|
| Size | 4.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9d1c7295712d98dd784fa31f7b280bb9794522f89a585d90c91c2e99ae34c4ba
|
|
BLAKE2b-256 checksum How to use checksums |
c57f4be9cf244b5a2340d04925cdae222285e57083e5b7432f2196bfc04df5c1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.6.1 requests/2.26.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.10
|
Release files / phxsocket-0.1.2-py3-none-any.whl
| Download URL | phxsocket-0.1.2-py3-none-any.whl |
|---|---|
| Size | 17.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8bf39542ef8eb9fd1cbcb79742dc984dae4cb6ba6a8773564912a127640abda4
|
|
BLAKE2b-256 checksum How to use checksums |
6532a5b3803b96ded56140288c328f1c0f30ec2277a378c8fd7d5e3883c53f3f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.6.1 requests/2.26.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.10
|