Skip to content

Commit

Permalink
updated docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
niklastheman committed Mar 16, 2024
1 parent d88e074 commit 1a3f332
Showing 1 changed file with 67 additions and 36 deletions.
103 changes: 67 additions & 36 deletions fedn/fedn/network/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def get_models(self, session_id: str = None, n_max: int = None):
:type session_id: str
:param n_max: The maximum number of models to get (If none all will be fetched).
:type n_max: int
:return: All models.
:return: Models.
:rtype: dict
"""
_params = {}
Expand Down Expand Up @@ -256,7 +256,7 @@ def get_model_trail(self, id: str = None, n_max: int = None):
:type id: str
:param n_max: The maximum number of models to get (If none all will be fetched).
:type n_max: int
:return: List of models.
:return: Models.
:rtype: dict
"""
if not id:
Expand Down Expand Up @@ -313,9 +313,9 @@ def set_model(self, path):
def get_package(self, id: str):
""" Get a compute package from the statestore.
:param id: The compute package id to get.
:param id: The id of the compute package to get.
:type id: str
:return: The compute package with info.
:return: Package.
:rtype: dict
"""
response = requests.get(self._get_url_api_v1(f'packages/{id}'), verify=self.verify, headers=self.headers)
Expand All @@ -325,9 +325,11 @@ def get_package(self, id: str):
return _json

def get_packages(self, n_max: int = None):
""" Get all compute packages from the statestore.
""" Get compute packages from the statestore.
:return: All compute packages with info.
:param n_max: The maximum number of packages to get (If none all will be fetched).
:type n_max: int
:return: Packages.
:rtype: dict
"""
_headers = self.headers.copy()
Expand All @@ -342,9 +344,9 @@ def get_packages(self, n_max: int = None):
return _json

def get_active_package(self):
""" Get the compute package from the statestore.
""" Get the (active) compute package from the statestore.
:return: The compute package with info.
:return: Package.
:rtype: dict
"""
response = requests.get(self._get_url_api_v1('packages/active'), verify=self.verify, headers=self.headers)
Expand All @@ -360,7 +362,7 @@ def get_package_checksum(self):
:rtype: dict
"""
response = requests.get(self._get_url('get_package_checksum'), verify=self.verify, headers=self.headers)

_json = response.json()

return _json
Expand Down Expand Up @@ -406,7 +408,7 @@ def get_round(self, id: str):
:param round_id: The round id to get.
:type round_id: str
:return: The round config and metrics.
:return: Round (config and metrics).
:rtype: dict
"""
response = requests.get(self._get_url_api_v1(f'rounds/{id}'), verify=self.verify, headers=self.headers)
Expand All @@ -418,7 +420,9 @@ def get_round(self, id: str):
def get_rounds(self, n_max: int = None):
""" Get all rounds from the statestore.
:return: All rounds with config and metrics.
:param n_max: The maximum number of rounds to get (If none all will be fetched).
:type n_max: int
:return: Rounds.
:rtype: dict
"""
_headers = self.headers.copy()
Expand All @@ -439,7 +443,7 @@ def get_session(self, id: str):
:param id: The session id to get.
:type id: str
:return: The session as a json object.
:return: Session.
:rtype: dict
"""

Expand All @@ -450,9 +454,11 @@ def get_session(self, id: str):
return _json

def get_sessions(self, n_max: int = None):
""" Get all sessions from the statestore.
""" Get sessions from the statestore.
:return: All sessions in dict.
:param n_max: The maximum number of sessions to get (If none all will be fetched).
:type n_max: int
:return: Sessions.
:rtype: dict
"""
_headers = self.headers.copy()
Expand All @@ -467,12 +473,12 @@ def get_sessions(self, n_max: int = None):
return _json

def get_session_status(self, id: str):
""" Check if a session with id id has finished.
""" Get the status of a session.
:param id: The session id to get.
:param id: The id of the session to get.
:type id: str
:return: The session as a json object.
:rtype: dict
:return: The status of the session.
:rtype: str
"""
session = self.get_session(id)

Expand All @@ -482,12 +488,12 @@ def get_session_status(self, id: str):
return "Could not retrieve session status."

def get_session_is_finished(self, id: str):
""" Check if a session with id id has finished.
""" Check if a session with id has finished.
:param id: The session id to get.
:param id: The id of the session to get.
:type id: str
:return: The session as a json object.
:rtype: dict
:return: True if session is finished, otherwise false.
:rtype: bool
"""
status = self.get_session_status(id)
return status and status.lower() == "finished"
Expand Down Expand Up @@ -551,11 +557,11 @@ def start_session(
# --- Statuses --- #

def get_status(self, id: str):
""" Get an event from the statestore.
""" Get a status object (event) from the statestore.
:param id: The event id to get.
:param id: The id of the status to get.
:type id: str
:return: The event in dict.
:return: Status.
:rtype: dict
"""
response = requests.get(self._get_url_api_v1(f'statuses/{id}'), verify=self.verify, headers=self.headers)
Expand All @@ -565,10 +571,19 @@ def get_status(self, id: str):
return _json

def get_statuses(self, session_id: str = None, event_type: str = None, sender_name: str = None, sender_role: str = None, n_max: int = None):
""" Get the events from the statestore. Pass kwargs to filter events.
""" Get statuses from the statestore. Filter by input parameters
:return: The events in dict
:rtype: dict
:param session_id: The session id to get statuses for.
:type session_id: str
:param event_type: The event type to get.
:type event_type: str
:param sender_name: The sender name to get.
:type sender_name: str
:param sender_role: The sender role to get.
:type sender_role: str
:param n_max: The maximum number of statuses to get (If none all will be fetched).
:type n_max: int
:return: Statuses
"""
_params = {}

Expand Down Expand Up @@ -600,9 +615,9 @@ def get_statuses(self, session_id: str = None, event_type: str = None, sender_na
def get_validation(self, id: str):
""" Get a validation from the statestore.
:param id: The validation id to get.
:param id: The id of the validation to get.
:type id: str
:return: The validation in dict.
:return: Validation.
:rtype: dict
"""
response = requests.get(self._get_url_api_v1(f'validations/{id}'), verify=self.verify, headers=self.headers)
Expand All @@ -622,9 +637,25 @@ def get_validations(
receiver_role: str = None,
n_max: int = None
):
""" Get all validations from the statestore. Pass kwargs to filter validations.
""" Get validations from the statestore. Filter by input parameters.
:return: All validations in dict.
:param session_id: The session id to get validations for.
:type session_id: str
:param model_id: The model id to get validations for.
:type model_id: str
:param correlation_id: The correlation id to get validations for.
:type correlation_id: str
:param sender_name: The sender name to get validations for.
:type sender_name: str
:param sender_role: The sender role to get validations for.
:type sender_role: str
:param receiver_name: The receiver name to get validations for.
:type receiver_name: str
:param receiver_role: The receiver role to get validations for.
:type receiver_role: str
:param n_max: The maximum number of validations to get (If none all will be fetched).
:type n_max: int
:return: Validations.
:rtype: dict
"""
_params = {}
Expand All @@ -640,13 +671,13 @@ def get_validations(

if sender_name:
_params["sender.name"] = sender_name

if sender_role:
_params["sender.role"] = sender_role

if receiver_name:
_params["receiver.name"] = receiver_name

if receiver_role:
_params["receiver.role"] = receiver_role

Expand All @@ -656,7 +687,7 @@ def get_validations(
_headers['X-Limit'] = str(n_max)

response = requests.get(self._get_url_api_v1('validations'), params=_params, verify=self.verify, headers=_headers)

_json = response.json()

return _json

0 comments on commit 1a3f332

Please sign in to comment.