pgwebsocket

Async websocket to PostgreSQL proxy.

Usage

from pgwebsocket import PgWebsocket

app = PgWebsocket("")

@app.on_connect
async def _on_connect(ctx):
    await ctx.execute("LISTEN clients;")

@app.on_disconnect
async def _on_disconnect(ctx):
    await ctx.execute("UNLISTEN clients;")

if __name__ == '__main__':
    app.run()

Installation

python3 -m pip install pgwebsocket

Proxy websocket messages to and from PostgreSQL.

Note: This dose not handle authentication and authorization, ensure you implement them at other layers.

class pgwebsocket.PgWebsocket(dburl: str, bind: str = '127.0.0.1', port: int = 9000)

An application to handle websocket to Postgresql proxying.

on_connect(callback: Callable[[...], Awaitable[bool]]) None

Register a callback after connection.

on_disconnect(callback: Callable[[...], Awaitable[bool]]) None

Register a callback after disconnection.

on_msg(route: str) Callable[[Callable[[...], Awaitable[bool]]], None]

Register a map of callbacks to handle diffrent messages.

Callbacks can return True to stop processing this message.

run(url: str = '/') None

Start listening for connections.

Indices and tables