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=None, secure=False, verify=False, token=None, auth_scheme=None)[source]
Bases:
object
An API client for interacting with the statestore and controller.
- Parameters:
- get_active_clients(combiner_id: str | None = None, n_max: int | None = None)[source]
Get active clients from the statestore.
- get_active_model()[source]
Get the latest model from the statestore.
- Returns:
The latest model.
- Return type:
- get_active_package()[source]
Get the (active) compute package from the statestore.
- Returns:
Package.
- Return type:
- get_client_config(checksum=True)[source]
Get client config from controller. Optionally include the checksum. The config is used for clients to connect to the controller and ask for combiner assignment.
- get_clients(n_max: int | None = None)[source]
Get clients from the statestore.
- Parameters:
n_max (int) – The maximum number of clients to get (If none all will be fetched).
return: Clients. rtype: dict
- get_clients_count()[source]
Get the number of clients in the statestore.
- Returns:
The number of clients.
- Return type:
- get_combiners_count()[source]
Get the number of combiners in the statestore.
- Returns:
The number of combiners.
- Return type:
- get_controller_status()[source]
Get the status of the controller.
- Returns:
The status of the controller.
- Return type:
- get_model_trail(id: str | None = None, include_self: bool = True, reverse: bool = True, n_max: int | None = None)[source]
Get the model trail.
- get_models(session_id: str | None = None, n_max: int | None = None)[source]
Get models from the statestore.
- get_models_count()[source]
Get the number of models in the statestore.
- Returns:
The number of models.
- Return type:
- get_package_checksum()[source]
Get the checksum of the compute package.
- Returns:
The checksum.
- Return type:
- get_packages_count()[source]
Get the number of compute packages in the statestore.
- Returns:
The number of packages.
- Return type:
- get_rounds_count()[source]
Get the number of rounds in the statestore.
- Returns:
The number of rounds.
- Return type:
- get_sessions_count()[source]
Get the number of sessions in the statestore.
- Returns:
The number of sessions.
- Return type:
- get_statuses(session_id: str | None = None, event_type: str | None = None, sender_name: str | None = None, sender_role: str | None = None, n_max: int | None = None)[source]
Get statuses from the statestore. Filter by input parameters
- get_statuses_count()[source]
Get the number of statuses in the statestore.
- Returns:
The number of statuses.
- Return type:
- get_validations(session_id: str | None = None, model_id: str | None = None, correlation_id: str | None = None, sender_name: str | None = None, sender_role: str | None = None, receiver_name: str | None = None, receiver_role: str | None = None, n_max: int | None = None)[source]
Get validations from the statestore. Filter by input parameters.
- Parameters:
session_id (str) – The session id to get validations for.
model_id (str) – The model id to get validations for.
correlation_id (str) – The correlation id to get validations for.
sender_name (str) – The sender name to get validations for.
sender_role (str) – The sender role to get validations for.
receiver_name (str) – The receiver name to get validations for.
receiver_role (str) – The receiver role to get validations for.
n_max (int) – The maximum number of validations to get (If none all will be fetched).
- Returns:
Validations.
- Return type:
- get_validations_count()[source]
Get the number of validations in the statestore.
- Returns:
The number of validations.
- Return type:
- set_active_model(path)[source]
Set the initial model in the statestore and upload to model repository.
- set_active_package(path: str, helper: str, name: str | None = None, description: str | None = None)[source]
Set the compute package in the statestore.
- start_session(id: str | None = None, aggregator: str = 'fedavg', aggregator_kwargs: dict | None = None, model_id: str | None = None, round_timeout: int = 180, rounds: int = 5, round_buffer_size: int = -1, delete_models: bool = True, validate: bool = True, helper: str = '', min_clients: int = 1, requested_clients: int = 8, server_functions: ServerFunctionsBase | None = None)[source]
Start a new session.
- Parameters:
id (str) – The session id to start.
aggregator (str) – The aggregator plugin to use.
model_id (str) – The id of the initial model.
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: