azad.slipstream Package¶
azad.slipstream ¶
Slipstream - A lightweight WebSocket-based network protocol implementation.
Classes¶
Protocol ¶
Complete, decorator-based protocol implementation.
Source code in azad/slipstream/base.py
Attributes¶
Functions¶
set_handler ¶
set_handler(handler: ProtocolHandler)
Attach a user-defined handler that has @request_response, etc. methods.
listen
async
¶
Reads messages from the websocket and dispatches them.
Source code in azad/slipstream/base.py
request_response
async
¶
Send a single request, wait for single response.
Source code in azad/slipstream/base.py
request_stream
async
¶
Send a request, get an async iterator of incoming items.
Source code in azad/slipstream/base.py
stream_stream
async
¶
stream_stream(data: dict) -> BiStreamHandle
Initiate a bi-directional stream, returning a handle.
Source code in azad/slipstream/base.py
ProtocolHandler ¶
A base class if you want to store reference to protocol, or do custom logic. Typically you just define your methods with the decorators directly.
Source code in azad/slipstream/base.py
MessageType ¶
Bases: Enum
Message types supported by the protocol.
ConnectionState ¶
ConnectionClosedError ¶
Bases: SlipstreamError
Raised when connection is closed normally (e.g. server shutdown).
Source code in azad/slipstream/base.py
ConnectionLostError ¶
Bases: SlipstreamError
Raised when connection is lost unexpectedly.
Source code in azad/slipstream/base.py
BiStreamHandle ¶
BiStreamHandle(protocol: Protocol, request_id: Tuple[str, int])
Manages a bi-directional stream with a particular request_id.
Source code in azad/slipstream/base.py
Attributes¶
Functions¶
send
async
¶
Send data to remote side as STREAM_DATA.
Source code in azad/slipstream/base.py
aclose
async
¶
Close our side of the stream (send STREAM_END).
WebSocketClient ¶
WebSocketClient(handler_factory: Callable[[Any], ProtocolHandler])
Initialize the WebSocket client.
Parameters:
-
handler_factory(Callable[[Any], ProtocolHandler]) –Function that creates a new ProtocolHandler instance
Source code in azad/slipstream/client.py
Attributes¶
Functions¶
connect
async
¶
Connect to a WebSocket server.
Parameters:
-
uri(str, default:'ws://localhost:8765') –The WebSocket URI to connect to
Source code in azad/slipstream/client.py
disconnect
async
¶
Disconnect from the WebSocket server.
Source code in azad/slipstream/client.py
request_response
async
¶
Send a request and wait for a response.
Parameters:
-
data–The request data to send
Returns:
-
–
The response data
Raises:
-
RuntimeError–If not connected
-
ConnectionClosedError–If connection closed normally
-
ConnectionLostError–If connection lost unexpectedly
Source code in azad/slipstream/client.py
request_stream
async
¶
Send a request and receive a stream of responses.
Parameters:
-
data–The request data to send
Returns:
-
–
An async iterator of response items
Raises:
-
RuntimeError–If not connected
-
ConnectionClosedError–If connection closed normally
-
ConnectionLostError–If connection lost unexpectedly
Source code in azad/slipstream/client.py
fire_and_forget
async
¶
Send a one-way message with no response.
Parameters:
-
data–The message data to send
Raises:
-
RuntimeError–If not connected
-
ConnectionClosedError–If connection closed normally
-
ConnectionLostError–If connection lost unexpectedly
Source code in azad/slipstream/client.py
create
async
classmethod
¶
create(handler_factory: Callable[[Any], ProtocolHandler], uri: str = 'ws://localhost:8765')
Create and connect a new WebSocket client.
Parameters:
-
handler_factory(Callable[[Any], ProtocolHandler]) –Function that creates a new ProtocolHandler instance
-
uri(str, default:'ws://localhost:8765') –The WebSocket URI to connect to
Returns:
-
–
A connected WebSocketClient instance
Source code in azad/slipstream/client.py
WebSocketServer ¶
WebSocketServer(handler_class: Callable[[Any], ProtocolHandler], host: str = 'localhost', port: int = 8765)
Initialize the WebSocket server.
Parameters:
-
handler_class(Callable[[Any], ProtocolHandler]) –Factory function that takes callbacks and returns a ProtocolHandler
-
host(str, default:'localhost') –The host to bind to
-
port(int, default:8765) –The port to listen on
Source code in azad/slipstream/server.py
Attributes¶
Functions¶
handle_connection
async
¶
Handle an incoming WebSocket connection.
Parameters:
-
websocket–The WebSocket connection to handle
Source code in azad/slipstream/server.py
start
async
¶
Start the WebSocket server.
Source code in azad/slipstream/server.py
stop
async
¶
Stop the WebSocket server.
Source code in azad/slipstream/server.py
create
async
classmethod
¶
create(handler_class: Callable[[Any], ProtocolHandler], host: str = 'localhost', port: int = 8765)
Create and start a new WebSocket server.
Parameters:
-
handler_class(Callable[[Any], ProtocolHandler]) –The ProtocolHandler class to use for new connections
-
host(str, default:'localhost') –The host to bind to
-
port(int, default:8765) –The port to listen on
Returns:
-
–
A running WebSocketServer instance
Source code in azad/slipstream/server.py
WebSocketNetworkProtocol ¶
WebSocketNetworkProtocol(handler_class: Optional[Callable[[Any], ProtocolHandler]] = None)
Bases: NetworkProtocol
WebSocket-based implementation of the NetworkProtocol interface.
Initialize the protocol.
Parameters:
-
handler_class(Optional[Callable[[Any], ProtocolHandler]], default:None) –Optional factory function to create protocol handlers. If not provided, a default handler will be used.
Source code in azad/slipstream/websocket.py
Functions¶
start_server
async
¶
Start the WebSocket server.
Parameters:
-
port(int) –Port to listen on
-
host(Optional[str]) –Host to bind to
Source code in azad/slipstream/websocket.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | |
stop_server
async
¶
Stop the WebSocket server.
Parameters:
-
grace_period(float, default:5.0) –Shutdown grace period in seconds
Source code in azad/slipstream/websocket.py
ProtocolCallbacks ¶
Bases: Protocol
Protocol interface defining required callback methods.
NetworkProtocol ¶
Bases: Protocol
Network protocol interface.
Functions¶
start_server
async
¶
start_server(port: int, callbacks: ProtocolCallbacks) -> None
Modules¶
base ¶
Attributes¶
Classes¶
SlipstreamError ¶
Bases: Exception
Base exception class for all slipstream errors.
ConnectionClosedError ¶
Bases: SlipstreamError
Raised when connection is closed normally (e.g. server shutdown).
Source code in azad/slipstream/base.py
ConnectionLostError ¶
Bases: SlipstreamError
Raised when connection is lost unexpectedly.
Source code in azad/slipstream/base.py
ProtocolError ¶
Bases: SlipstreamError
Raised when there is a protocol-level error.
ConnectionState ¶
MessageType ¶
Bases: Enum
Message types supported by the protocol.
FrameModel ¶
Bases: BaseModel
Source code in azad/slipstream/base.py
BiStreamHandle ¶
BiStreamHandle(protocol: Protocol, request_id: Tuple[str, int])
Manages a bi-directional stream with a particular request_id.
Source code in azad/slipstream/base.py
async
¶Send data to remote side as STREAM_DATA.
Source code in azad/slipstream/base.py
async
¶Close our side of the stream (send STREAM_END).
Protocol ¶
Complete, decorator-based protocol implementation.
Source code in azad/slipstream/base.py
set_handler(handler: ProtocolHandler)
Attach a user-defined handler that has @request_response, etc. methods.
async
¶Reads messages from the websocket and dispatches them.
Source code in azad/slipstream/base.py
async
¶Send a single request, wait for single response.
Source code in azad/slipstream/base.py
async
¶Send a request, get an async iterator of incoming items.
Source code in azad/slipstream/base.py
async
¶stream_stream(data: dict) -> BiStreamHandle
Initiate a bi-directional stream, returning a handle.
Source code in azad/slipstream/base.py
ProtocolHandler ¶
A base class if you want to store reference to protocol, or do custom logic. Typically you just define your methods with the decorators directly.
Source code in azad/slipstream/base.py
Functions¶
validate_incoming_frame ¶
validate_incoming_frame(frame_data: str) -> FrameModel
Convert raw JSON → dict → FrameModel, raising if invalid.
Source code in azad/slipstream/base.py
client ¶
WebSocket client implementation.
Attributes¶
Classes¶
WebSocketClient ¶
WebSocketClient(handler_factory: Callable[[Any], ProtocolHandler])
Initialize the WebSocket client.
Parameters:
-
handler_factory(Callable[[Any], ProtocolHandler]) –Function that creates a new ProtocolHandler instance
Source code in azad/slipstream/client.py
async
¶Connect to a WebSocket server.
Parameters:
-
uri(str, default:'ws://localhost:8765') –The WebSocket URI to connect to
Source code in azad/slipstream/client.py
async
¶Disconnect from the WebSocket server.
Source code in azad/slipstream/client.py
async
¶Send a request and wait for a response.
Parameters:
-
data–The request data to send
Returns:
-
–
The response data
Raises:
-
RuntimeError–If not connected
-
ConnectionClosedError–If connection closed normally
-
ConnectionLostError–If connection lost unexpectedly
Source code in azad/slipstream/client.py
async
¶Send a request and receive a stream of responses.
Parameters:
-
data–The request data to send
Returns:
-
–
An async iterator of response items
Raises:
-
RuntimeError–If not connected
-
ConnectionClosedError–If connection closed normally
-
ConnectionLostError–If connection lost unexpectedly
Source code in azad/slipstream/client.py
async
¶Send a one-way message with no response.
Parameters:
-
data–The message data to send
Raises:
-
RuntimeError–If not connected
-
ConnectionClosedError–If connection closed normally
-
ConnectionLostError–If connection lost unexpectedly
Source code in azad/slipstream/client.py
async
classmethod
¶create(handler_factory: Callable[[Any], ProtocolHandler], uri: str = 'ws://localhost:8765')
Create and connect a new WebSocket client.
Parameters:
-
handler_factory(Callable[[Any], ProtocolHandler]) –Function that creates a new ProtocolHandler instance
-
uri(str, default:'ws://localhost:8765') –The WebSocket URI to connect to
Returns:
-
–
A connected WebSocketClient instance
Source code in azad/slipstream/client.py
Functions¶
run_client
async
¶
run_client(handler_factory: Callable[[Any], ProtocolHandler], uri: str = 'ws://localhost:8765')
Run a WebSocket client until interrupted.
Parameters:
-
handler_factory(Callable[[Any], ProtocolHandler]) –Function that creates a new ProtocolHandler instance
-
uri(str, default:'ws://localhost:8765') –The WebSocket URI to connect to
Source code in azad/slipstream/client.py
server ¶
WebSocket server implementation.
Attributes¶
Classes¶
WebSocketServer ¶
WebSocketServer(handler_class: Callable[[Any], ProtocolHandler], host: str = 'localhost', port: int = 8765)
Initialize the WebSocket server.
Parameters:
-
handler_class(Callable[[Any], ProtocolHandler]) –Factory function that takes callbacks and returns a ProtocolHandler
-
host(str, default:'localhost') –The host to bind to
-
port(int, default:8765) –The port to listen on
Source code in azad/slipstream/server.py
async
¶Handle an incoming WebSocket connection.
Parameters:
-
websocket–The WebSocket connection to handle
Source code in azad/slipstream/server.py
async
¶Start the WebSocket server.
Source code in azad/slipstream/server.py
async
¶Stop the WebSocket server.
Source code in azad/slipstream/server.py
async
classmethod
¶create(handler_class: Callable[[Any], ProtocolHandler], host: str = 'localhost', port: int = 8765)
Create and start a new WebSocket server.
Parameters:
-
handler_class(Callable[[Any], ProtocolHandler]) –The ProtocolHandler class to use for new connections
-
host(str, default:'localhost') –The host to bind to
-
port(int, default:8765) –The port to listen on
Returns:
-
–
A running WebSocketServer instance
Source code in azad/slipstream/server.py
Functions¶
run_server
async
¶
run_server(handler_class: Callable[[Any], ProtocolHandler], host: str = 'localhost', port: int = 8765)
Run a WebSocket server until interrupted.
Parameters:
-
handler_class(Callable[[Any], ProtocolHandler]) –The ProtocolHandler class to use for new connections
-
host(str, default:'localhost') –The host to bind to
-
port(int, default:8765) –The port to listen on
Source code in azad/slipstream/server.py
websocket ¶
WebSocket-based network protocol implementation.
Attributes¶
Classes¶
ProtocolCallbacks ¶
Bases: Protocol
Protocol interface defining required callback methods.
NetworkProtocol ¶
Bases: Protocol
Network protocol interface.
async
¶start_server(port: int, callbacks: ProtocolCallbacks) -> None
WebSocketNetworkProtocol ¶
WebSocketNetworkProtocol(handler_class: Optional[Callable[[Any], ProtocolHandler]] = None)
Bases: NetworkProtocol
WebSocket-based implementation of the NetworkProtocol interface.
Initialize the protocol.
Parameters:
-
handler_class(Optional[Callable[[Any], ProtocolHandler]], default:None) –Optional factory function to create protocol handlers. If not provided, a default handler will be used.
Source code in azad/slipstream/websocket.py
async
¶Start the WebSocket server.
Parameters:
-
port(int) –Port to listen on
-
host(Optional[str]) –Host to bind to
Source code in azad/slipstream/websocket.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | |
async
¶Stop the WebSocket server.
Parameters:
-
grace_period(float, default:5.0) –Shutdown grace period in seconds