ClientApp#

class ClientApp(client_fn: Callable[[str], Client] | None = None, mods: List[Callable[[Message, Context, Callable[[Message, Context], Message]], Message]] | None = None)[source]#

Bases : object

Flower ClientApp.

Exemples

Assuming a typical Client implementation named FlowerClient, you can wrap it in a ClientApp as follows:

>>> class FlowerClient(NumPyClient):
>>>     # ...
>>>
>>> def client_fn(cid):
>>>    return FlowerClient().to_client()
>>>
>>> app = ClientApp(client_fn)

If the above code is in a Python module called client, it can be started as follows:

>>> flower-client-app client:app --insecure

In this client:app example, client refers to the Python module client.py in which the previous code lives in and app refers to the global attribute app that points to an object of type ClientApp.

Methods

evaluate()

Return a decorator that registers the evaluate fn with the client app.

query()

Return a decorator that registers the query fn with the client app.

train()

Return a decorator that registers the train fn with the client app.

evaluate() Callable[[Callable[[Message, Context], Message]], Callable[[Message, Context], Message]][source]#

Return a decorator that registers the evaluate fn with the client app.

Exemples

>>> app = ClientApp()
>>>
>>> @app.evaluate()
>>> def evaluate(message: Message, context: Context) -> Message:
>>>    print("ClientApp evaluation running")
>>>    # Create and return an echo reply message
>>>    return message.create_reply(content=message.content())
query() Callable[[Callable[[Message, Context], Message]], Callable[[Message, Context], Message]][source]#

Return a decorator that registers the query fn with the client app.

Exemples

>>> app = ClientApp()
>>>
>>> @app.query()
>>> def query(message: Message, context: Context) -> Message:
>>>    print("ClientApp query running")
>>>    # Create and return an echo reply message
>>>    return message.create_reply(content=message.content())
train() Callable[[Callable[[Message, Context], Message]], Callable[[Message, Context], Message]][source]#

Return a decorator that registers the train fn with the client app.

Exemples

>>> app = ClientApp()
>>>
>>> @app.train()
>>> def train(message: Message, context: Context) -> Message:
>>>    print("ClientApp training running")
>>>    # Create and return an echo reply message
>>>    return message.create_reply(content=message.content())