nvflare.apis.fl_context module

class FLContext[source]

Bases: object

Init the FLContext.

The FLContext is used to passed data between FL Components. It can be thought of as a dictionary that stores key/value pairs called props (properties).

Visibility: private props are only visible to local components,

public props are also visible to remote components

Stickiness: sticky props become available in all future FL Contexts,

non-sticky props will only be available in the current FL Context

get_all_public_props() Dict[str, Any][source]
get_custom_prop(key: str, default=None)[source]
get_prop(key, default=None)[source]
get_prop_keys() List[str][source]
public_key_exists(key) bool[source]
put(key: str, value, private, sticky)[source]

Simply put the prop into the fl context without doing sticky property processing :param key: :param value: :param private: :param sticky:


remove_prop(key: str, force_removal=False)[source]
set_custom_prop(key: str, value)[source]
set_job_is_unsafe(value: bool = True)[source]
set_prop(key: str, value, private=True, sticky=True)[source]
set_public_props(metadata: dict)[source]
class FLContextManager(engine=None, identity_name: str = '', job_id: str = '', public_stickers=None, private_stickers=None)[source]

Bases: object

FLContextManager manages the creation and updates of FLContext objects for a run.

NOTE: The engine may create a new FLContextManager object for each RUN!

Init the FLContextManager.

  • engine – the engine that created this FLContextManager object

  • identity_name (str) – identity name

  • job_id – the job id

  • public_stickers – public sticky properties that are copied into or copied from

  • private_stickers – private sticky properties that are copied into or copied from

check_sticker(key: str) -> (<class 'bool'>, typing.Any, <class 'int'>)[source]

Check whether a sticky prop exists in either the public or private group.


key – the key of the sticker to be checked

Returns: tuple: whether the sticker exists, its value and mask if it exists

new_context() FLContext[source]

Create a new FLContext object.

Sticky properties are copied from the stickers into the new context.

Returns: a FLContext object

update_sticker(key: str, value, mask)[source]

Update the value of a specified sticker.

  • key – key of the sticker to be updated

  • value – value of the sticker

  • mask – mask to determine whether the sticker is public or private


is_private(mask) bool[source]
is_sticky(mask) bool[source]
make_mask(private, sticky)[source]
to_string(mask) str[source]