nvflare.lighter.entity module¶
- class Entity(scope: str, name: str, props: dict, parent=None)[source]¶
Bases:
object
- get_prop_fb(key: str, fb_key=None, default=None)[source]¶
Get property value with fallback. If I have the property, then return it. If not, I return the fallback property of my parent. If I don’t have parent, return default.
- Parameters:
key – key of the property
fb_key – key of the fallback property.
default – value to return if no one has the property
Returns: property value
- class Participant(type: str, name: str, org: str, props: dict | None = None, project: Entity | None = None)[source]¶
Bases:
Entity
Class to represent a participant.
Each participant communicates to other participant. Therefore, each participant has its own name, type, organization it belongs to, rules and other information.
- Parameters:
type (str) – server, client, admin, relay or other string that builders can handle
name (str) – system-wide unique name
org (str) – system-wide unique organization
props (dict) – properties
project – the project that the participant belongs to
- Raises:
ValueError – if name or org is not compliant with characters or format specification.
- get_connect_to() ConnectTo | None [source]¶
Get the connect_to property of the participant
Returns: a ConnectTo object
- get_default_host() str [source]¶
Get the default host name for accessing this participant (server). If the “default_host” attribute is explicitly specified, then it’s the default host. If the “default_host” attribute is not explicitly specified, then use the “name” attribute.
Returns: a host name
- get_listening_host() ListeningHost | None [source]¶
Get listening host property of the participant
Returns: a ListeningHost object, or None if the property is not defined.
- class Project(name: str, description: str, participants=None, props: dict | None = None, serialized_root_cert=None, root_private_key=None)[source]¶
Bases:
Entity
A container class to hold information about this FL project.
This class only holds information. It does not drive the workflow.
- Parameters:
name (str) – the project name
description (str) – brief description on this name
participants – if provided, list of participants of the project
props – properties of the project
serialized_root_cert – if provided, the root cert to be used for the project
root_private_key – if provided, the root private key for signing certs of sites and admins
- Raises:
ValueError – when participant criteria is violated
- add_admin(name: str, org: str, props: dict) Participant [source]¶
Add an admin user to the project
- Parameters:
name – name of the admin user.
org – org of the admin user.
props – properties of the user definition
Returns: a Participant object of the admin user
- add_client(name: str, org: str, props: dict) Participant [source]¶
Add a client to the project
- Parameters:
name – name of the client
org – org of the client
props – additional properties of the client
Returns: the Participant object of the client
- add_participant(participant: Participant) Participant [source]¶
Add a participant to the project. Before adding the participant, this method checks the following conditions: - All participants in the project must have unique names - Only one server is allowed in the project - Only one overseer is allowed in the project - Role must be specified for admin type of participant
- Parameters:
participant – the participant to be added.
Returns: the participant object added.
- add_relay(name: str, org: str, props: dict) Participant [source]¶
Add a relay to the project
- Parameters:
name – name of the relay
org – org of the relay
props – additional properties of the relay
Returns: the relay Participant object
- get_admins() List[Participant] [source]¶
Get the list of admin users
Returns: list of admin users
- get_all_participants(types: None | str | List[str] = None)[source]¶
Get all participants of the project of specified types.
- Parameters:
types – types of the participants to be returned.
- Returns: all participants of the project of specified types.
If ‘types’ is not specified (None), it returns all participants of the project; If ‘types’ is a str, it is treated as a single type and participants of this type is returned; If ‘types’ is a list of types, participants of these types are returned;
- get_clients() List[Participant] [source]¶
Get all clients of the project
Returns: a list of clients
- get_overseer() Participant | None [source]¶
Get the overseer definition. Only one overseer is supported!
Returns: overseer participant
- get_relays() List[Participant] [source]¶
Get all relays of the project
Returns: the list of relays of the project
- get_server() Participant | None [source]¶
Get the server definition. Only one server is supported!
Returns: server participant
- set_overseer(name: str, org: str, props: dict) Participant [source]¶
- set_server(name: str, org: str, props: dict) Participant [source]¶
Set the server of the project.
- Parameters:
name – name of the server.
org – org of the server
props – additional server properties.
Returns: a Participant object for the server
- parse_connect_to(value, scope=None, prop_key=None) ConnectTo [source]¶
Parse the “connect_to” property.
- Parameters:
value – value to be parsed. It is either a str or a dict.
scope – scope of the property
prop_key – key of the property
Returns: a ConnectTo object
- parse_listening_host(value, scope=None, prop_key=None) ListeningHost [source]¶
Parse the “listening_host” property. It must be either str or a dict
- Parameters:
value – value to be parsed
scope – scope of the prop
prop_key – key of the property
Returns: a ListeningHost object
- participant_from_dict(participant_def: dict) Participant [source]¶
Create a Participant from a dict that contains participant property definitions.
- Parameters:
participant_def – the dict that contains participant definition
Returns: a Participant object