API Reference
- ydl.DEFAULT_HOST: str
The default host that the server and client bind to.
- ydl.DEFAULT_PORT: int
The default port that the server and client bind to.
- class ydl.Client(*receive_channels: str, host: str = '127.0.0.1', port: int = 5001)
A client to the YDL network. Listens to a set of channels, and may send messages to any channel. Will automatically try to connect to YDL network.
- receive() Tuple
Blocks while waiting for next message. Will try to reconnect if connection is lost.
- send(message: Tuple)
The input message is a tuple of (target_channel, stuff…). target_channel is a string which identifies the channel you want to send to. stuff can be any other stuff you want to send. stuff must be json serializable. This method may block if disconnected and waiting for a new connection.
- class ydl.Handler
A handler object is meant to store a bunch of functions, then call the corresponding function whenever a header is received
- can_handle(message: Tuple) bool
Returns True if the message is well-formed, and there exists a corresponding function for the handler to call.
- handle(message: Tuple) Tuple
If the message is well-formed and an applicable function exists for the given message, calls that function and returns a single-element tuple (result,), where result is the return value of the function. Otherwise, returns an empty tuple. Note that (result,) is truthy and an empty tuple is falsy.
- on(header_fn)
This decorator annotates a function that the handler should call whenever the given header is received. The original function is returned by the decorator, so a function can be annotated multiple times.
- ydl.header(channel, name)
Decorator that turns a regular function into a “header function”. The header function calls the original function (so it can do input validation), then returns a message in this format: (channel, name, args) where args is a dictionary of the arguments
- ydl.run_server(host: str = '127.0.0.1', port: int = 5001, verbose: bool = False)
Runs the YDL server that processes will use to communicate with each other