flwr.common package

Flower utilities shared between server and client.

class flwr.common.Disconnect(reason: str)[source]

Bases: object

Disconnect message from client to server.

reason: str
class flwr.common.EvaluateIns(parameters: flwr.common.typing.Parameters, config: Dict[str, str])[source]

Bases: object

Evaluate instructions for a client.

config: Dict[str, str]
parameters: Parameters
class flwr.common.EvaluateRes(num_examples: int, loss: float, accuracy: float)[source]

Bases: object

Evaluate response from a client.

accuracy: float
loss: float
num_examples: int
class flwr.common.FitIns(parameters: flwr.common.typing.Parameters, config: Dict[str, str])[source]

Bases: object

Fit instructions for a client.

config: Dict[str, str]
parameters: Parameters
class flwr.common.FitRes(parameters: flwr.common.typing.Parameters, num_examples: int, num_examples_ceil: int, fit_duration: float)[source]

Bases: object

Fit response from a client.

fit_duration: float
num_examples: int
num_examples_ceil: int
parameters: Parameters
class flwr.common.Parameters(tensors: List[bytes], tensor_type: str)[source]

Bases: object

Model parameters.

tensor_type: str
tensors: List[bytes]
class flwr.common.ParametersRes(parameters: flwr.common.typing.Parameters)[source]

Bases: object

Response when asked to return parameters.

parameters: Parameters
class flwr.common.Reconnect(seconds: Optional[int])[source]

Bases: object

Reconnect message from server to client.

seconds: Optional[int]
flwr.common.Weights

The central part of internal API.

This represents a generic version of type ‘origin’ with type arguments ‘params’. There are two kind of these aliases: user defined and special. The special ones are wrappers around builtin collections and ABCs in collections.abc. These must have ‘name’ always set. If ‘inst’ is False, then the alias can’t be instantiated, this is used by e.g. typing.List and typing.Dict.

alias of List[numpy.ndarray]

flwr.common.bytes_to_ndarray(tensor: bytes) → numpy.ndarray[source]

Deserialize NumPy array from bytes.

flwr.common.ndarray_to_bytes(ndarray: numpy.ndarray) → bytes[source]

Serialize NumPy array to bytes.

flwr.common.parameters_to_weights(parameters: flwr.common.typing.Parameters) → List[numpy.ndarray][source]

Convert parameters object to NumPy weights.

flwr.common.weights_to_parameters(weights: List[numpy.ndarray])flwr.common.typing.Parameters[source]

Convert NumPy weights to parameters object.

Submodules

flwr.common.logger module

Flower Logger.

class flwr.common.logger.CustomHTTPHandler(identifier: str, host: str, url: str, method: str = 'GET', secure: bool = False, credentials: Optional[Tuple[str, str]] = None)[source]

Bases: logging.handlers.HTTPHandler

Custom HTTPHandler which overrides the mapLogRecords method.

mapLogRecord(record: logging.LogRecord) → Dict[str, Any][source]

Filter for the properties to be send to the logserver.

flwr.common.logger.configure(identifier: str, filename: Optional[str] = None, host: Optional[str] = None) → None[source]

Configure logging to file and/or remote log server.

flwr.common.parameter module

Parameter conversion.

flwr.common.parameter.bytes_to_ndarray(tensor: bytes) → numpy.ndarray[source]

Deserialize NumPy array from bytes.

flwr.common.parameter.ndarray_to_bytes(ndarray: numpy.ndarray) → bytes[source]

Serialize NumPy array to bytes.

flwr.common.parameter.parameters_to_weights(parameters: flwr.common.typing.Parameters) → List[numpy.ndarray][source]

Convert parameters object to NumPy weights.

flwr.common.parameter.weights_to_parameters(weights: List[numpy.ndarray])flwr.common.typing.Parameters[source]

Convert NumPy weights to parameters object.

flwr.common.serde module

This module contains functions for protobuf serialization and deserialization.

flwr.common.serde.disconnect_from_proto(msg: flwr.proto.transport_pb2.Disconnect)flwr.common.typing.Disconnect[source]

Deserialize flower.Disconnect from ProtoBuf message.

flwr.common.serde.disconnect_to_proto(disconnect: flwr.common.typing.Disconnect) → flwr.proto.transport_pb2.Disconnect[source]

Serialize flower.Disconnect to ProtoBuf message.

flwr.common.serde.evaluate_ins_from_proto(msg: flwr.proto.transport_pb2.EvaluateIns)flwr.common.typing.EvaluateIns[source]

Deserialize flower.EvaluateIns from ProtoBuf message.

flwr.common.serde.evaluate_ins_to_proto(ins: flwr.common.typing.EvaluateIns) → flwr.proto.transport_pb2.EvaluateIns[source]

Serialize flower.EvaluateIns to ProtoBuf message.

flwr.common.serde.evaluate_res_from_proto(msg: flwr.proto.transport_pb2.EvaluateRes)flwr.common.typing.EvaluateRes[source]

Deserialize flower.EvaluateRes from ProtoBuf message.

flwr.common.serde.evaluate_res_to_proto(res: flwr.common.typing.EvaluateRes) → flwr.proto.transport_pb2.EvaluateRes[source]

Serialize flower.EvaluateIns to ProtoBuf message.

flwr.common.serde.fit_ins_from_proto(msg: flwr.proto.transport_pb2.FitIns)flwr.common.typing.FitIns[source]

Deserialize flower.FitIns from ProtoBuf message.

flwr.common.serde.fit_ins_to_proto(ins: flwr.common.typing.FitIns) → flwr.proto.transport_pb2.FitIns[source]

Serialize flower.FitIns to ProtoBuf message.

flwr.common.serde.fit_res_from_proto(msg: flwr.proto.transport_pb2.FitRes)flwr.common.typing.FitRes[source]

Deserialize flower.FitRes from ProtoBuf message.

flwr.common.serde.fit_res_to_proto(res: flwr.common.typing.FitRes) → flwr.proto.transport_pb2.FitRes[source]

Serialize flower.FitIns to ProtoBuf message.

flwr.common.serde.get_parameters_to_proto() → flwr.proto.transport_pb2.GetParameters[source]

.

flwr.common.serde.parameters_from_proto(msg: flwr.proto.transport_pb2.Parameters)flwr.common.typing.Parameters[source]

.

flwr.common.serde.parameters_res_from_proto(msg: flwr.proto.transport_pb2.ParametersRes)flwr.common.typing.ParametersRes[source]

.

flwr.common.serde.parameters_res_to_proto(res: flwr.common.typing.ParametersRes) → flwr.proto.transport_pb2.ParametersRes[source]

.

flwr.common.serde.parameters_to_proto(parameters: flwr.common.typing.Parameters) → flwr.proto.transport_pb2.Parameters[source]

.

flwr.common.serde.reconnect_from_proto(msg: flwr.proto.transport_pb2.Reconnect)flwr.common.typing.Reconnect[source]

Deserialize flower.Reconnect from ProtoBuf message.

flwr.common.serde.reconnect_to_proto(reconnect: flwr.common.typing.Reconnect) → flwr.proto.transport_pb2.Reconnect[source]

Serialize flower.Reconnect to ProtoBuf message.

flwr.common.typing module

Flower type definitions.

class flwr.common.typing.Disconnect(reason: str)[source]

Bases: object

Disconnect message from client to server.

reason: str
class flwr.common.typing.EvaluateIns(parameters: flwr.common.typing.Parameters, config: Dict[str, str])[source]

Bases: object

Evaluate instructions for a client.

config: Dict[str, str]
parameters: Parameters
class flwr.common.typing.EvaluateRes(num_examples: int, loss: float, accuracy: float)[source]

Bases: object

Evaluate response from a client.

accuracy: float
loss: float
num_examples: int
class flwr.common.typing.FitIns(parameters: flwr.common.typing.Parameters, config: Dict[str, str])[source]

Bases: object

Fit instructions for a client.

config: Dict[str, str]
parameters: Parameters
class flwr.common.typing.FitRes(parameters: flwr.common.typing.Parameters, num_examples: int, num_examples_ceil: int, fit_duration: float)[source]

Bases: object

Fit response from a client.

fit_duration: float
num_examples: int
num_examples_ceil: int
parameters: Parameters
class flwr.common.typing.Parameters(tensors: List[bytes], tensor_type: str)[source]

Bases: object

Model parameters.

tensor_type: str
tensors: List[bytes]
class flwr.common.typing.ParametersRes(parameters: flwr.common.typing.Parameters)[source]

Bases: object

Response when asked to return parameters.

parameters: Parameters
class flwr.common.typing.Reconnect(seconds: Optional[int])[source]

Bases: object

Reconnect message from server to client.

seconds: Optional[int]