Alfalfa API Client Documentation

The Alfalfa API Client provides a python interface for interacting with an Alfalfa instance.

class alfalfa_client.alfalfa_client.AlfalfaClient(host: str = 'http://localhost', api_version: str = 'v2')

AlfalfaClient is a wrapper for the Alfalfa REST API

advance(run_id: str | List[str]) None

Advance a run 1 timestep

Parameters:

run_id – id of run or list of ids

create_run_from_model(model_id: str | List[str], wait_for_status: bool = True) str

Create a run from a model

Parameters:
  • model_id – id of model to create a run from or list of ids

  • wait_for_status – wait for model to be “READY” before returning

Returns:

id of run created

get_alias(alias: str) str

Get run_id from alias

Parameters:

alias – alias

Returns:

Id of run associated with alias

get_error_log(run_id: str | List[str]) str

Get error log from run

Parameters:

run_id – id of run or list of ids

Returns:

error log from run

get_inputs(run_id: str) List[str]

Get inputs of run

Parameters:

run_id – id of run

Returns:

list of input names

get_outputs(run_id: str) dict

Get outputs of run

Parameters:

run_id – id of run

Returns:

dictionary of output names and values

get_sim_time(run_id: str | List[str]) datetime

Get sim_time of run

Parameters:

run_id – id of site or list of ids

Returns:

datetime of site

set_alias(alias: str, run_id: str) None

Set alias to point to a run_id

Parameters:
  • run_id – id of run to point alias to

  • alias – alias to use

set_inputs(run_id: str, inputs: dict) None

Set inputs of run

Parameters:
  • run_id – id of run

  • inputs – dictionary of point names and input values

start(run_id: str | List[str], start_datetime: datetime, end_datetime: datetime, timescale: int = 5, external_clock: bool = False, realtime: bool = False, wait_for_status: bool = True)

Start one run from a model.

Parameters:
  • run_id – id of run or list of ids

  • start_datetime – time to start the model from

  • end_datetime – time to stop the model at (may not be honored for external_clock=True)

  • timescale – multiple of real time to run model at (for external_clock=False)

  • external_clock – run model with an external advancer

  • realtime – run model with timescale=1

  • wait_for_status – wait for model to be “RUNNING” before returning

status(run_id: str | List[str]) str

Get status of run

Parameters:

run_id – id of run or list of ids

Returns:

status of run

stop(run_id: str | List[str], wait_for_status: bool = True)

Stop a run

Parameters:
  • run_id – id of the run or list of ids

  • wait_for_status – wait for the run to be “complete” before returning

submit(model_path: str | List[str], wait_for_status: bool = True) str

Submit a model to alfalfa

Parameters:
  • model_path – path to the model to upload or list of paths

  • wait_for_status – wait for model to be “READY” before returning

Returns:

id of created run

Return type:

str

upload_model(model_path: PathLike) str

Upload a model to alfalfa

Parameters:

model_path – path to model file or folder or list of paths

Returns:

id of model

wait(run_id: str | List[str], desired_status: str, timeout: float = 600) None

Wait for a run to have a certain status or timeout with error

Parameters:
  • run_id – id of run or list of ids

  • desired_status – status to wait for

  • timeout – timeout length in seconds

Indices and tables