fedn.network.api package

API module for the FEDn network. Includes a REST-API server to interact with the controller and statestore.

Submodules

fedn.network.api.client module

class fedn.network.api.client.APIClient(host, port, secure=False, verify=False)[source]

Bases: object

An API client for interacting with the statestore and controller.

Parameters:
  • host (str) – The host of the api server.

  • port (int) – The port of the api server.

  • secure (bool) – Whether to use https.

  • verify (bool) – Whether to verify the server certificate.

download_package(path)[source]

Download the compute package.

Parameters:

path (str) – The path to download the compute package to.

Returns:

Message with success or failure.

Return type:

dict

get_active_clients(combiner_id)[source]

Get all active clients from the statestore.

Parameters:

combiner_id (str) – The combiner id to get active clients for.

Returns:

All active clients.

Return type:

dict

get_client_config(checksum=True)[source]

Get the controller configuration. Optionally include the checksum. The config is used for clients to connect to the controller and ask for combiner assignment.

Parameters:

checksum (bool) – Whether to include the checksum of the package.

Returns:

The client configuration.

Return type:

dict

get_combiner(combiner_id)[source]

Get a combiner from the statestore.

Parameters:

combiner_id (str) – The combiner id to get.

Returns:

The combiner info.

Return type:

dict

get_controller_status()[source]

Get the status of the controller.

Returns:

The status of the controller.

Return type:

dict

get_events(**kwargs)[source]

Get the events from the statestore. Pass kwargs to filter events.

Returns:

The events in dict

Return type:

dict

get_initial_model()[source]

Get the initial model from the statestore.

Returns:

The initial model id.

Return type:

dict

get_latest_model()[source]

Get the latest model from the statestore.

Returns:

The latest model id.

Return type:

dict

get_model_trail()[source]

Get the model trail.

Returns:

The model trail as dict including commit timestamp.

Return type:

dict

get_package()[source]

Get the compute package from the statestore.

Returns:

The compute package with info.

Return type:

dict

get_package_checksum()[source]

Get the checksum of the compute package.

Returns:

The checksum.

Return type:

dict

get_round(round_id)[source]

Get a round from the statestore.

Parameters:

round_id (str) – The round id to get.

Returns:

The round config and metrics.

Return type:

dict

get_session(session_id)[source]

Get a session from the statestore.

Parameters:

session_id (str) – The session id to get.

Returns:

The session as a json object.

Return type:

dict

list_clients()[source]

Get all clients from the statestore.

return: All clients. rtype: dict

list_combiners()[source]

Get all combiners in the network.

Returns:

All combiners with info.

Return type:

dict

list_compute_packages()[source]

Get all compute packages from the statestore.

Returns:

All compute packages with info.

Return type:

dict

list_models(session_id=None)[source]

Get all models from the statestore.

Returns:

All models.

Return type:

dict

list_rounds()[source]

Get all rounds from the statestore.

Returns:

All rounds with config and metrics.

Return type:

dict

list_sessions()[source]

Get all sessions from the statestore.

Returns:

All sessions in dict.

Return type:

dict

list_validations(**kwargs)[source]

Get all validations from the statestore. Pass kwargs to filter validations.

Returns:

All validations in dict.

Return type:

dict

set_initial_model(path)[source]

Set the initial model in the statestore and upload to model repository.

Parameters:

path (str) – The file path of the initial model to set.

Returns:

A dict with success or failure message.

Return type:

dict

set_package(path: str, helper: str, name: str | None = None, description: str | None = None)[source]

Set the compute package in the statestore.

Parameters:
  • path (str) – The file path of the compute package to set.

  • helper (str) – The helper type to use.

Returns:

A dict with success or failure message.

Return type:

dict

start_session(session_id=None, round_timeout=180, rounds=5, round_buffer_size=-1, delete_models=True, validate=True, helper='kerashelper', min_clients=1, requested_clients=8)[source]

Start a new session.

Parameters:
  • session_id (str) – The session id to start.

  • round_timeout (int) – The round timeout to use in seconds.

  • rounds (int) – The number of rounds to perform.

  • round_buffer_size (int) – The round buffer size to use.

  • delete_models (bool) – Whether to delete models after each round at combiner (save storage).

  • validate (bool) – Whether to validate the model after each round.

  • helper (str) – The helper type to use.

  • min_clients (int) – The minimum number of clients required.

  • requested_clients (int) – The requested number of clients.

Returns:

A dict with success or failure message and session config.

Return type:

dict

fedn.network.api.interface module

class fedn.network.api.interface.API(statestore, control)[source]

Bases: object

The API class is a wrapper for the statestore. It is used to expose the statestore to the network API.

add_client(client_id, preferred_combiner, remote_addr)[source]

Add a client to the network.

Parameters:
  • client_id (str) – The client id to add.

  • preferred_combiner (str) – The preferred combiner for the client.If None, the combiner will be chosen based on availability.

Returns:

A json response with combiner assignment config.

Return type:

flask.Response

add_combiner(combiner_id, secure_grpc, address, remote_addr, fqdn, port)[source]

Add a combiner to the network.

Parameters:
  • combiner_id (str) – The combiner id to add.

  • secure_grpc (bool) – Whether to use secure grpc or not.

  • name (str) – The name of the combiner.

  • address (str) – The address of the combiner.

  • remote_addr (str) – The remote address of the combiner.

  • fqdn (str) – The fqdn of the combiner.

  • port (int) – The port of the combiner.

Returns:

Config of the combiner as a json response.

Return type:

flask.Response

download_compute_package(name)[source]

Download the compute package.

Returns:

The compute package as a json object.

Return type:

flask.Response

get_all_combiners(limit=None, skip=None)[source]

Get all combiners from the statestore.

Returns:

All combiners as a json response.

Return type:

flask.Response

get_all_rounds()[source]

Get all rounds.

Returns:

The rounds as json response.

Return type:

flask.Response

get_all_sessions(limit=None, skip=None)[source]

Get all sessions from the statestore.

Returns:

All sessions as a json response.

Return type:

flask.Response

get_all_validations(**kwargs)[source]

Get all validations from the statestore.

Returns:

All validations as a json response.

Return type:

flask.Response

get_checksum(name)[source]

Get the checksum of the compute package.

Parameters:

name (str) – The name of the compute package.

Returns:

The checksum as a json object.

Return type:

flask.Response

get_client_config(checksum=True)[source]

Get the client config.

Returns:

The client config as json response.

Return type:

flask.Response

get_clients(limit=None, skip=None, status=False)[source]

Get all clients from the statestore.

Returns:

All clients as a json response.

Return type:

flask.Response

get_combiner(combiner_id)[source]

Get a combiner from the statestore.

Parameters:

combiner_id (str) – The combiner id to get.

Returns:

The combiner info dict as a json response.

Return type:

flask.Response

get_compute_package()[source]

Get the compute package from the statestore.

Returns:

The compute package as a json response.

Return type:

flask.Response

get_controller_status()[source]

Get the status of the controller.

Returns:

The status of the controller as a json object.

Return type:

flask.Response

get_events(**kwargs)[source]

Get the events of the federated network.

Returns:

The events as a json object.

Return type:

flask.Response

get_initial_model()[source]

Get the initial model from the statestore.

Returns:

The initial model as a json response.

Return type:

flask.Response

get_latest_model()[source]

Get the latest model from the statestore.

Returns:

The initial model as a json response.

Return type:

flask.Response

get_model_trail()[source]

Get the model trail for a given session.

Parameters:

session (str) – The session id to get the model trail for.

Returns:

The model trail for the given session as a json response.

Return type:

flask.Response

get_models(session_id: str | None = None, limit: str | None = None, skip: str | None = None, include_active: str | None = None)[source]
get_plot_data(feature=None)[source]

Get plot data.

Returns:

The plot data as json response.

Return type:

flask.Response

get_round(round_id)[source]

Get a round.

Parameters:

round_id (str) – The round id to get.

Returns:

The round as json response.

Return type:

flask.Response

get_session(session_id)[source]

Get a session from the statestore.

Parameters:

session_id (str) – The session id to get.

Returns:

The session info dict as a json response.

Return type:

flask.Response

list_combiners_data(combiners)[source]

Get combiners data.

Parameters:

combiners (list) – The combiners to get data for.

Returns:

The combiners data as json response.

Return type:

flask.Response

list_compute_packages(limit: str | None = None, skip: str | None = None, include_active: str | None = None)[source]

Get paginated list of compute packages from the statestore. :param limit: The number of compute packages to return. :type limit: str :param skip: The number of compute packages to skip. :type skip: str :param include_active: Whether to include the active compute package or not. :type include_active: str :return: All compute packages as a json response. :rtype: flask.Response

set_active_compute_package(id: str)[source]
set_compute_package(file, helper_type: str, name: str | None = None, description: str | None = None)[source]

Set the compute package in the statestore.

Parameters:

file (file) – The compute package to set.

Returns:

A json response with success or failure message.

Return type:

flask.Response

set_current_model(model_id: str)[source]

Set the active model in the statestore.

Parameters:

model_id (str) – The model id to set.

Returns:

A json response with success or failure message.

Return type:

flask.Response

set_initial_model(file)[source]

Add an initial model to the network.

Parameters:

file (file) – The initial model to add.

Returns:

A json response with success or failure message.

Return type:

flask.Response

start_session(session_id, rounds=5, round_timeout=180, round_buffer_size=-1, delete_models=False, validate=True, helper='keras', min_clients=1, requested_clients=8)[source]

Start a session.

Parameters:
  • session_id (str) – The session id to start.

  • rounds (int) – The number of rounds to perform.

  • round_timeout (int) – The round timeout to use in seconds.

  • round_buffer_size (int) – The round buffer size to use.

  • delete_models (bool) – Whether to delete models after each round at combiner (save storage).

  • validate (bool) – Whether to validate the model after each round.

  • min_clients (int) – The minimum number of clients required.

  • requested_clients (int) – The requested number of clients.

Returns:

A json response with success or failure message and session config.

Return type:

flask.Response

fedn.network.api.network module

class fedn.network.api.network.Network(control, statestore, load_balancer=None)[source]

Bases: object

FEDn network interface. This class is used to interact with the network. Note: This class contain redundant code, which is not used in the current version of FEDn. Some methods has been moved to fedn.network.api.interface.API.

add_client(client)[source]

Add a new client to the network.

Parameters:

client (dict) – The client instance object

Returns:

None

add_combiner(combiner)[source]

Add a new combiner to the network.

Parameters:

combiner (fedn.network.combiner.interfaces.CombinerInterface) – The combiner instance object

Returns:

None

find_available_combiner()[source]

Find an available combiner in the network.

Returns:

The combiner instance object

Return type:

fedn.network.combiner.interfaces.CombinerInterface

get_client(name)[source]

Get client by name.

Parameters:

name (str) – name of client

Returns:

The client instance object

Return type:

ObjectId

get_client_info()[source]

list available client in statestore.

Returns:

list of client objects

Return type:

list(ObjectId)

get_combiner(name)[source]

Get combiner by name.

Parameters:

name (str) – name of combiner

Returns:

The combiner instance object

Return type:

fedn.network.combiner.interfaces.CombinerInterface

get_combiners()[source]

Get all combiners in the network.

Returns:

list of combiners objects

Return type:

list(fedn.network.combiner.interfaces.CombinerInterface)

handle_unavailable_combiner(combiner)[source]

This callback is triggered if a combiner is found to be unresponsive.

Parameters:

combiner (fedn.network.combiner.interfaces.CombinerInterface) – The combiner instance object

Returns:

None

remove_combiner(combiner)[source]

Remove a combiner from the network.

Parameters:

combiner (fedn.network.combiner.interfaces.CombinerInterface) – The combiner instance object

Returns:

None

update_client_data(client_data, status, role)[source]

Update client status in statestore.

Parameters:
  • client_data (dict) – The client instance object

  • status (str) – The client status

  • role (str) – The client role

Returns:

None