Python Client

class cs_kit.api.ComputeStudio(owner: str, title: str, api_token: Optional[str] = None)[source]

Python client for the ComputeStudio webapp.

  • Run simulations

  • Update simulation metadata

  • Download your results

client = ComputeStudio("PSLmodels", "TaxBrain")
client.create()

Learn how to get your API token from the Authentication docs. Once you have your token, you can save it in a file named .cs_api_token in the home directory of your computer. You can also set it as an environment variable or pass it directly to the ComputeStudio class.

create(adjustment: Optional[dict] = None, meta_parameters: Optional[dict] = None)[source]

Create a simulation on Compute Studio.

Parameters
  • adjustment (dict) – Parameter values in the ParamTools format.

  • meta_parameters (dict) – Meta parameters for the simulation in a key:value format.

Returns

response – Response from the Compute Studio server. Use this to get the simulation ID and status.

Return type

dict

detail(model_pk: int, include_outputs: bool = False, wait: bool = True, polling_interval: int = 5, timeout: int = 600)[source]

Get detail for a simulation.

Parameters
  • model_pk (int) – ID for the simulation.

  • include_outputs (bool) – Include outputs from the simulation in addition to the simulation metadata.

  • wait (bool) – Meta parameters for the simulation in a key:value format.

  • polling_interval (int) – Polling interval dictates how often the status of the results will be checked.

  • timeout (int) – Time in seconds to wait for the simulation to finish.

Returns

response – Response from the Compute Studio server.

Return type

dict

get_token(api_token)[source]

Retrieve the API token

inputs(model_pk: Optional[int] = None)[source]

Get the inputs for a simulation or retrieve the inputs documentation for the app.

Parameters

model_pk (int) – ID for the simulation.

Returns

response – Response from the Compute Studio server.

Return type

dict

results(model_pk: int, timeout: int = 600)[source]

Retrieve and parse results into the appropriate data structure. Currently, CSV outputs are loaded into a pandas DataFrame. Other outputs are returned as is.

Parameters
  • model_pk (int) – ID for the simulation.

  • timeout (int) – Time in seconds to wait for the simulation to finish.

Returns

result – Dictionary of simulation outputs formated as title:output.

Return type

dict

update(model_pk: int, title: Optional[str] = None, is_public: Optional[bool] = None, notify_on_completion: Optional[bool] = None)[source]

Update meta data about a simulation.

cs.update(
    model_pk=123,
    title="hello world",
    is_public=True,
    notify_on_completion=True
)
Parameters
  • model_pk (int) – ID for the simulation.

  • title (str) – Title of the simulation.

  • is_public (bool) – Set whether simulation is public or private.

  • Notify_on_completion (bool) – Send an email notification when the simulation completes.

Returns

response – Response from the Compute Studio server.

Return type

dict