Client#

class zonis.Client[source]#

Bases: RouteHandler

Parameters:
  • reconnect_attempt_count (int) – The number of times that the Client should attempt to reconnect.

  • url (str) – Defaults to ws://localhost.

  • port (Optional[int]) – The port that the Client should use.

async block_until_closed()[source]#

A blocking call which releases when the WS closes.

async start() None[source]#

Start the IPC client.

async close() None[source]#

Stop the IPC client.

async request(route: str, **kwargs)[source]#

Make a request to the server

add_route(*, route_name: str, callback) RouteHandler#

Programmatically adds a route.

Parameters:
  • route_name (str) – The name of the route.

  • callback – The callback attached to the route.

Returns:

Returns the current instance for method chaining.

Return type:

RouteHandler

load_routes() None#

Loads all decorated routes.

register_class_instance_for_routes(instance, *routes) None#

Register a class instance for the given route.

When you turn a method on a class into an IPC route, you need to call this method with the instance of the class to use as well as the names of the routes for registration to work correctly.

Parameters:
  • instance – The class instance the methods live on

  • routes – A list of strings representing the names of the IPC routes for this class.

remove_route(route_name: str) RouteHandler#

Programmatically removes a route.

Parameters:

route_name (str) – The route to remove

Returns:

Returns the current instance for method chaining.

Return type:

RouteHandler

Notes

Raises no error if the route doesn’t exist.

route(route_name: Optional[str] = None)#

Turn an async function into a valid IPC route.

Parameters:

route_name (Optional[str]) – An optional name for this IPC route, defaults to the name of the function.

Raises:

DuplicateRoute – A route with this name already exists

Notes

If this is a method on a class, you will also need to use the register_class_instance_for_routes method for this to work as an IPC route.