Skip to main content

pondsocket-asgi

Canonical ASGI adapter for pondsocket. Mount under any ASGI host — FastAPI, Starlette, Litestar, Django, raw uvicorn.

Handles WebSocket and SSE (Server-Sent Events) transports. The same PondSocket instance serves both — the adapter detects the request type and dispatches.

Install

pip install pondsocket-asgi

Pulls in pondsocket and pondsocket-common automatically.

Quick start: raw uvicorn

from pondsocket import ConnectionContext, EventContext, JoinContext, PondSocket
from pondsocket_asgi import PondASGIApp


async def auth(ctx: ConnectionContext) -> None:
    ctx.accept()


async def on_join(ctx: JoinContext) -> None:
    await ctx.accept()


async def on_message(ctx: EventContext) -> None:
    await ctx.broadcast(ctx.event_name, ctx.get_payload())


pond = PondSocket()
endpoint = pond.create_endpoint("/socket", auth)
lobby = endpoint.create_channel("/chat/:room_id", on_join)
lobby.on_message("message", on_message)

app = PondASGIApp(pond)
uvicorn module:app --host 127.0.0.1 --port 8000

WebSocket clients connect to ws://127.0.0.1:8000/socket.

Mount under FastAPI

from fastapi import FastAPI
from pondsocket_asgi import PondASGIApp

app = FastAPI()
app.mount("/ws", PondASGIApp(pond))

When mounted at /ws, the adapter sees scope["path"] already stripped of the prefix — register your pond endpoints with the post-mount path (e.g. /socket resolves at ws://host/ws/socket).

See examples/ for FastAPI, Starlette, and raw uvicorn variants.

SSE transport

The same endpoint serves Server-Sent Events to clients that don't have WebSocket:

GET /socket
  Accept: text/event-stream
→ 200, response carries X-Connection-ID header and a `CONNECTION` event with `payload.connectionId`, stream of "event: <name>\ndata: <json>\n\n" frames

POST /socket
  X-Connection-ID: <id>
  Content-Type: application/json
  body: <client message JSON>
→ 204

DELETE /socket
  X-Connection-ID: <id>
→ 204

Use SSE when WebSocket is blocked (some corporate proxies). The connection handler is the same — the adapter routes by Accept header and method.

Lifespan

PondASGIApp handles the ASGI lifespan protocol. On lifespan.startup, it acknowledges immediately. On lifespan.shutdown, it closes the PondSocket (which closes every endpoint, every channel, every transport).

Testing

pondsocket_asgi.testing exposes an in-memory ASGI driver — no real network needed:

from pondsocket_asgi.testing import ASGITestDriver

driver = ASGITestDriver(PondASGIApp(pond))

# WebSocket
session = await driver.connect_websocket("/socket")
await session.send_client_message(
    action="JOIN_CHANNEL",
    channel_name="/chat/1",
    event="join",
)
ack = await session.receive_json()
await session.disconnect()

# SSE
sse = await driver.connect_sse("/socket")
status, _ = await driver.sse_push(sse.connection_id, {"action": "BROADCAST", ...})
frame = await sse.receive_event()
await sse.disconnect()

# Lifespan
lifespan = await driver.open_lifespan()
await lifespan.startup()
await lifespan.shutdown()

Public API

from pondsocket_asgi import ...

  • PondASGIApp — the adapter itself
  • ASGIWebSocketTransport — WebSocket transport (you usually don't construct this directly; the app does)

from pondsocket_asgi.testing import ...

  • ASGITestDriver, WebSocketSession, LifespanSession, SSESession

License

GPL-3.0-or-later.

Metadata

Release files for pondsocket-asgi 0.0.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pondsocket-asgi 0.0.7
File Size Uploaded Provenance Actions
pondsocket_asgi-0.0.7.tar.gz 13.1 kB Without provenance Details for pondsocket_asgi-0.0.7.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pondsocket-asgi 0.0.7
File Interpreter ABI Platform Actions
pondsocket_asgi-0.0.7-py3-none-any.whl Python 3 none any Details for pondsocket_asgi-0.0.7-py3-none-any.whl

Total release size: 24.9 kB

Release files / pondsocket_asgi-0.0.7.tar.gz

Download URL pondsocket_asgi-0.0.7.tar.gz
Size 13.1 kB
Tags Source
SHA-256 checksum
How to use checksums
1b14f74be9eeb7d16bc85990e538afdb0eb60f6e7c1fb045164304a56d430da1
BLAKE2b-256 checksum
How to use checksums
db84cb54867e0075f76f1adbf52059ae7ec98b1171e6ef2232573fd4762afbca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.0

Release files / pondsocket_asgi-0.0.7-py3-none-any.whl

Download URL pondsocket_asgi-0.0.7-py3-none-any.whl
Size 11.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c981e54ccf533078f23df5b0f634968c28c99fb92416afe0f8c4a79a550e4d85
BLAKE2b-256 checksum
How to use checksums
9de548dba73a6fcb66da5947e4b58a9131ac1efaa5dcc74946cd3ec9f79f2cc3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.0

Security for pondsocket-asgi 0.0.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page