Skip to main content

PondSocket Python client — connect to a PondSocket server from Python.

Project description

pondsocket-client

Python client for the PondSocket server. Connects to PondSocket servers (Python, Go, or TypeScript implementation) over WebSocket.

Modeled after the JavaScript client architecture (@eleven-am/pondsocket-client) rather than the Go one — the JS client fixes several bugs the Go client has (see Parity notes below).

Install

pip install pondsocket-client

Quick start

import asyncio
from pondsocket_client import PondClient


async def main() -> None:
    client = PondClient("ws://localhost:8000/ws", {"token": "secret"})
    await client.connect()

    channel = client.create_channel("/chat/42", {"username": "alice"})
    channel.on_message_event("message", lambda m: print(m.payload))
    channel.on_join(lambda user: print("joined:", user))
    channel.join()

    channel.send_message("message", {"text": "hello"})

    response = await channel.send_for_response("ping", {"text": "abc"})
    print("got pong:", response)

    await asyncio.sleep(10)
    await client.disconnect()


asyncio.run(main())

Architecture

BaseClient (abstract)
  ├── channel registry
  ├── inbound event routing (ACK / UNAUTHORIZED / CONNECTION / per-channel)
  ├── connection state machine: DISCONNECTED → CONNECTING → CONNECTED
  └── exponential reconnect

WebSocketClient(BaseClient)  (abstract)
  ├── opens via `websockets` library
  └── receive loop pumps inbound to BaseClient

PondClient(WebSocketClient)  (concrete)
  ├── URL handling (http → ws, https → wss)
  └── appends query-string params

The Channel class holds the per-channel state machine (IDLE → JOINING → JOINED → STALLED → CLOSED/DECLINED), a bounded outbound queue (drops oldest on overflow), and a send_for_response that correlates inbound replies by requestId.

Connection states

Subscribe via client.on_connection_change(handler):

State When
DISCONNECTED initial; after disconnect or socket close
CONNECTING connect() called; socket handshake in flight
CONNECTED socket open AND server sent the CONNECTION event

Channel states

Subscribe via channel.on_channel_state_change(handler):

State Meaning
IDLE created but join() not called
JOINING join() called; awaiting ACKNOWLEDGE
JOINED server acknowledged; messages flow
STALLED socket dropped while JOINED; will rejoin on reconnect
CLOSED leave() called
DECLINED server sent UNAUTHORIZED; channel is terminal — create a new one

Parity notes

Compared to the Go client (go/pondsocket-client/):

Behavior Go Python
send_for_response correlation event name (buggy) requestId (correct)
Reconnect backoff linear despite comment true exponential, capped
UNAUTHORIZED handling not implemented DECLINED state
Connection state bool (no CONNECTING) three-state enum
Outbound queue unbounded bounded, drops oldest
Join while disconnected dropped silently deferred until CONNECTED

The Python client follows the JS client design where the two diverge.

Public API

from pondsocket_client import (
    PondClient,
    Channel,
    ConnectionState,
    ClientOptions,
    ResponseTimeoutError,
)

Also exposed for adapter authors: BaseClient, WebSocketClient, Publisher (type alias).

License

GPL-3.0-or-later.

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

pondsocket_client-0.0.3.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

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

pondsocket_client-0.0.3-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file pondsocket_client-0.0.3.tar.gz.

File metadata

  • Download URL: pondsocket_client-0.0.3.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for pondsocket_client-0.0.3.tar.gz
Algorithm Hash digest
SHA256 1a57dcf708dd7117091d9596ee879eee8e7830c69892dced6e23ce32702d8541
MD5 656d2a66579c5befd706b465fc7cc2b0
BLAKE2b-256 07e1fd9ee84cedca704f645e67044872f42dceebe4c0f67f921fc33075cde5a3

See more details on using hashes here.

File details

Details for the file pondsocket_client-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: pondsocket_client-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for pondsocket_client-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2e71002289362ad0c5723d0624bdadd479611cabf2a8767ac1d777d28b71e8ce
MD5 91950f8d27cafda1ec3ea810f4084a6c
BLAKE2b-256 fb3208ca5133cae3189ca456d5d0a0d4af40d754cae54b416afc05e7fd92e11e

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