strangeworks.core.client package

Submodules

strangeworks.core.client.auth module

auth.py.

strangeworks.core.client.auth.get_token(api_key: str, base_url: str) str

Obtain a bearer token using an API key.

Parameters:
  • api_key (str) – Users API key. Obtained from users workspace.

  • base_url (str) – Base URL to access auth endpoint on platform.

Returns:

A JWT token which can be used to access workspace resources, files, etc.

Return type:

str

strangeworks.core.client.backends module

backends.py.

class strangeworks.core.client.backends.Backend(id: str, data: dict, data_schema: str, name: str, remote_backend_id: str, remote_status: str, slug: str)

Bases: object

Represents a Strangeworks platform Backend.

data: dict
data_schema: str
static from_dict(backend: dict) Backend

Create backend object from dictionary.

id: str
name: str
remote_backend_id: str
remote_status: str
slug: str
strangeworks.core.client.backends.get_backend(client: SDKAPI, slug: str) Backend

Retrieve backend info for a specific backend identified by slug.

strangeworks.core.client.backends.get_backends(client: SDKAPI, product_slugs: List[str] | None = None, backend_type_slugs: List[str] | None = None, backend_statuses: List[str] | None = None, backend_tags: List[str] | None = None) List[Backend]

Retrieve a list of available backends.

Does not fetch data to reduce size of payload.

strangeworks.core.client.experiments module

class strangeworks.core.client.experiments.Experiment(name: str, trials: list[Trial])

Bases: object

An experiment.

name

Name of the experiment.

Type:

str

trials

List of trials associated with the experiment.

Type:

list[Trial]

name: str
trials: list[Trial]
class strangeworks.core.client.experiments.ExperimentConfiguration(experiment_name: str | None = None, trial_name: str | None = None, requirements_path: str | None = None, local_run: bool = False)

Bases: object

Configuration for the experiment.

experiment_name

Name of the experiment, by default None. If None, the experiment name will be the name of the function.

Type:

Optional[str], optional

trial_name

Name of the trial, by default None If None, the trial name will be the name of the function.

Type:

Optional[str], optional

requirements_path

Path to a requirements.txt file, by default None The requirements.txt defines the dependencies required to run the experiment.

Type:

Optional[str], optional

local_run

If True, run the experiment locally, by default False This allows you to test the experiment locally before submitting.

Type:

bool, optional

experiment_name: str | None = None
local_run: bool = False
requirements_path: str | None = None
trial_name: str | None = None
class strangeworks.core.client.experiments.ExperimentInput(experiment_name: str, trial_name: str, fargs: tuple[any] = (), fkwargs: dict[str, any] = <factory>)

Bases: object

Input to the experiment.

experiment_name

Name of the experiment.

Type:

str

trial_name

Name of the trial.

Type:

str

fargs

Positional arguments to the function, by default ()

Type:

tuple[any], optional

fkwargs

Keyword arguments to the function, by default {}

Type:

dict[str, any], optional

experiment_name: str
fargs: tuple[any] = ()
fkwargs: dict[str, any]
trial_name: str
class strangeworks.core.client.experiments.Trial(name: str, status: str | None, files: list[File], jobs: list[Job] | None = None)

Bases: object

An experiment trial.

name

Name of the trial.

Type:

str

status

Trial status.

Type:

Optional[str]

files

List of files associated with the trial.

Type:

list[File]

jobs

List of jobs associated with the trial, by default None

Type:

Optional[list[Job]], optional

files: list[File]
jobs: list[Job] | None = None
name: str
status: str | None
class strangeworks.core.client.experiments.TrialSubmission(success: bool, message: str, output: any | None = None)

Bases: object

Output of the experiment.

success

Whether the experiment was successfully submitted.

Type:

bool

message

Message about the experiment.

Type:

str

output

Output of the experiment, by default None This output is only available if the experiment was run locally.

Type:

Optional[any], optional

message: str
output: any | None = None
success: bool
strangeworks.core.client.experiments.get_experiment(api: API, name: str, trials: int | list[str], files: str | list[str], jobs: bool | list[str]) Experiment

get_experiment returns an experiment object.

Parameters:
  • api (API) – Strangeworks API object.

  • name (str) – Name of the experiment.

  • trials (Union[int, list[str]]) – Number of trials to return or a list of trial names.

  • files (Union[str, list[str]]) – Name of the file or a list of file names.

  • jobs (Union[bool, list[str]]) – If True, return jobs associated with the trials. If a list of job slugs is provided, return only those jobs.

Returns:

An experiment object. Filled with the trials requested. Each trial will have the files requested (if the particular trial has them). Each trial will have the jobs requested (if the particular trial has them).

Return type:

Experiment

strangeworks.core.client.experiments.run(api: API, func: Callable[[...], any], input: ExperimentInput | list[ExperimentInput], cfg: ExperimentConfiguration = ExperimentConfiguration(experiment_name=None, trial_name=None, requirements_path=None, local_run=False), **kwargs) dict[str, TrialSubmission]

Run a function as a batch job on the Strangeworks platform.

Parameters:
  • api (API) – Strangeworks API object.

  • func (Callable[..., any]) – The function to run.

  • input (Union[ExperimentInput, list[ExperimentInput]]) – The input to the function. If a list is provided, each element will be run as a separate batch job.

  • cfg (ExperimentConfiguration, optional) – Configuration for the experiment, by default ExperimentConfiguration()

Returns:

A dictionary of trial names to TrialSubmission objects.

Return type:

dict[str, TrialSubmission]

strangeworks.core.client.experiments.upload_exp_file(api: API, experiment_name: str, trial_name: str, path: str, is_public: bool = False, name: str | None = None, json_schema: str | None = None, label: str | None = None, content_type: str | None = None) tuple[File, str]

upload_exp_file uploads a file to an experiment.

Parameters:
  • api (API) – Strangeworks API object.

  • experiment_name (str) – Name of the experiment.

  • trial_name (str) – Name of the trial.

  • path (str) – Path to the file.

  • is_public (bool, optional) – Whether the file is public, by default False

  • name (Optional[str], optional) – Name of the file, by default None

  • json_schema (Optional[str], optional) – JSON schema of the file, by default None

  • label (Optional[str], optional) – Label of the file, by default None

  • content_type (Optional[str], optional) – Content type of the file, by default None

Returns:

A tuple of the File object and the signed URL. The signed URL is where the file can be uploaded.

Return type:

tuple[File, str]

strangeworks.core.client.file module

file.py.

class strangeworks.core.client.file.File(*, slug: str, file_id: str | None = None, label: str | None = None, file_name: str | None = None, url: str | None = None, date_created: datetime | None = None, date_updated: datetime | None = None, content: Any = None, data_schema_slug: str | None = None, local_path: Path | None = None)

Bases: File

Class representing files on the platform for SDK users.

content

Content of the file. Defaults to None.

Type:

any | None

data_schema_slug

Optional data schema slug. Defaults to None.

Type:

str | None

content: Any
data_schema_slug: str | None
classmethod from_dict(data: dict) File

Generate File object from dictionary.

Parameters:

data (dict) – File object represented as a dictionary.

Returns:

File object.

Return type:

File

property id: str

Retrieve File ID.

This is an internal identifier used by the platform and should only be used for debugging, etc.

Added for backward compatibility.

local_path: Path | None
model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'content': FieldInfo(annotation=Any, required=False, default=None), 'data_schema_slug': FieldInfo(annotation=Union[str, NoneType], required=False, default=None), 'date_created': FieldInfo(annotation=Union[datetime, NoneType], required=False, default=None, alias=AliasChoices(choices=['date_created', 'dateCreated']), alias_priority=2), 'date_updated': FieldInfo(annotation=Union[datetime, NoneType], required=False, default=None, alias=AliasChoices(choices=['date_updated', 'dateUpdated']), alias_priority=2), 'file_id': FieldInfo(annotation=Union[str, NoneType], required=False, default=None, alias=AliasChoices(choices=['id', 'file_id']), alias_priority=2), 'file_name': FieldInfo(annotation=Union[str, NoneType], required=False, default=None, alias=AliasChoices(choices=['file_name', 'fileName']), alias_priority=2), 'label': FieldInfo(annotation=Union[str, NoneType], required=False, default=None), 'local_path': FieldInfo(annotation=Union[Path, NoneType], required=False, default=None), 'slug': FieldInfo(annotation=str, required=True), 'url': FieldInfo(annotation=Union[str, NoneType], required=False, default=None)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

strangeworks.core.client.file.upload(client: SDKAPI, workspace_slug: str, path: str, is_public: bool = False, name: str | None = None, json_schema: str | None = None, label: str | None = None, content_type: str | None = None) Tuple[File, str]

Upload a file to the associated workspace.

Parameters:
  • client (StrangeworksGQLClient) – client to access the platform api.

  • workspace_slug (str) – identifies which workspace the file is associated with.

  • path (str) – fully qualified path to the file.

  • is_public (bool) – if True, this file may be accessed by the URL with no authentication. In general, most files should NOT be public.

  • name (Optional[str]) – file name. Optional as we look at the path for the file name.

  • json_schema (Optional[str]) – if the file contains json, this is an identifier or link to a json schema which corresponds to the file contents. If the file contents adhere to a schema, it is highly recommended that this field is populated.

  • label (Optional[str]) – An optional label that will be displayed to users in the portal instead of the file name. Used by the platform portal.

  • content_type (Optional[str]) – The content_type of the file. Defaults to application/x-www-form-urlencoded. Once you PUT to the signed url, the content-type header must match this value.

Returns:

  • File – Object with information about the file that was uploaded.

  • Str – A signed url to PUT the file.

strangeworks.core.client.jobs module

jobs.py.

class strangeworks.core.client.jobs.Job(*, remote_id: str | None = None, remote_status: str | None = None, slug: str, job_id: str | None = None, external_identifier: str | None = None, status: Status | None = None, is_platform_terminal_state: bool | None = None, job_data: Dict[str, Any] | None = None, job_data_schema: str | None = None, date_created: datetime | None = None, date_updated: datetime | None = None, resource: Resource | None = None, child_jobs: List[Job] | None = None, files: List[File] | None = None)

Bases: Job

Class for SDK Jobs.

child_jobs: List[Job] | None
files: List[File] | None
list_files(include_child_job_files: bool = False) List[File] | None

Return list of files associated with job.

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'child_jobs': FieldInfo(annotation=Union[List[Job], NoneType], required=False, default=None), 'date_created': FieldInfo(annotation=Union[datetime, NoneType], required=False, default=None, alias=AliasChoices(choices=['date_created', 'dateCreated']), alias_priority=2), 'date_updated': FieldInfo(annotation=Union[datetime, NoneType], required=False, default=None, alias=AliasChoices(choices=['date_updated', 'dateUpdated']), alias_priority=2), 'external_identifier': FieldInfo(annotation=Union[str, NoneType], required=False, default=None, alias=AliasChoices(choices=['external_identifier', 'externalIdentifier']), alias_priority=2, serialization_alias='externalIdentifier'), 'files': FieldInfo(annotation=Union[List[File], NoneType], required=False, default=None), 'is_platform_terminal_state': FieldInfo(annotation=Union[bool, NoneType], required=False, default=None, alias=AliasChoices(choices=['is_terminal_state', 'isTerminalState']), alias_priority=2, serialization_alias='isTerminalState'), 'job_data': FieldInfo(annotation=Union[Dict[str, Any], NoneType], required=False, default=None, alias=AliasChoices(choices=['job_data', 'jobData', 'data']), alias_priority=2, serialization_alias='jobData'), 'job_data_schema': FieldInfo(annotation=Union[str, NoneType], required=False, default=None, alias=AliasChoices(choices=['job_data_schema', 'jobDataSchema', 'dataSchema']), alias_priority=2), 'job_id': FieldInfo(annotation=Union[str, NoneType], required=False, default=None, alias=AliasChoices(choices=['id', 'job_id']), alias_priority=2), 'remote_id': FieldInfo(annotation=Union[str, NoneType], required=False, default=None), 'remote_status': FieldInfo(annotation=Union[str, NoneType], required=False, default=None, alias_priority=2, validation_alias=AliasChoices(choices=['remote_status', 'remoteStatus']), serialization_alias='remoteStatus'), 'resource': FieldInfo(annotation=Union[Resource, NoneType], required=False, default=None), 'slug': FieldInfo(annotation=str, required=True), 'status': FieldInfo(annotation=Union[Status, NoneType], required=False, default=None)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

strangeworks.core.client.jobs.get(client: SDKAPI, job_slug: str | None = None, resource_slugs: List[str] | None = None, product_slugs: List[str] | None = None, statuses: List[str] | None = None, tags: List[str] | None = None, batch_size: int = 50) List[Job] | None

Return list of jobs associated with the current workspace.

If no parameters (other than client) are specified, the function will return all jobs associated with the current workspace account.Caller can filter results through specifying parameters. The filters are cumulative, meaning only jobs matching all specified criteria will be returned.

Parameters:
  • client (StrangeworksGQLClient) – client to access the sdk api on the platform.

  • job_slub (Optional[str]) – Filter to retrieve only the job whose slug matches. Defaults to None.

  • resource_slugs (Optional[List[str]]) – List of resource identifiers. Only jobs with matching resource will be returned. Defaults to None.

  • product_slugs (Optional[List[str]]) – List of product identifiers called slugs. Only jobs for matching products will be retuned. Defaults to None.

  • statuses (Optional[List[str]]) – List of job statuses. Only jobs whose statuses match will be returned. Defaults to None.

  • batch_size (int) – Number of jobs to retrieve with each request. Defaults to 50.

Returns:

List of Job objects that match the given criteria.

Return type:

Optional[List[Job]]

strangeworks.core.client.resource module

resources.py.

strangeworks.core.client.resource.get(client: SDKAPI, resource_slug: str | None = None) List[Resource] | None

Retrieve a list of available resources.

Parameters:

resource_slug (Optional[str]) – If supplied, only the resource whose slug matches will be returned. Defaults to None.

Returns:

List of resources or None if workspace has no resources configured.

Return type:

Optional[List[Resource]]

strangeworks.core.client.rest_client module

rest_client.py.

class strangeworks.core.client.rest_client.StrangeworksRestClient(host: str, headers: Dict[str, str] | None = None, api_key: str | None = None, auth_token: str | None = None, session: Session | None = None, default_timeout: int | None = None, version: str = '', **kwargs)

Bases: object

Strangeworks REST client.

ALLOWED_REQUEST_KWARGS = ['params', 'data', 'json', 'headers', 'cookies', 'files', 'auth', 'timeout', 'allow_redirects', 'proxies', 'verify', 'stream', 'cert']
create_session() Session

Create a requests.Session object for interacting with Strangeworks.

Returns:

session – The session object created by requests.

Return type:

requests.Session

delete(url: str = '', expected_response: int = 200) None

Issue a DELETE request to the given URL.

Parameters:
  • url (str) – The endpoint to delete.

  • expected_response (int, optional, default is 200) – The expected response from the endpoint.

get(url: str = '') Dict[str, Any]

Use the session to issue a GET.

Parameters:

url (str) – The URL to perform the GET request.

Returns:

res – The JSON response.

Return type:

dict

get_host() str

Return host/base url.

post(url: str = '', json: Dict[str, Any] | None = None, files: Dict[str, Any] | None = None, data: Dict[str, Any] | None = None, expected_response: int = 200, **kvargs) Dict[str, Any]

Send a POST command to the given URL endpoint.

Parameters:
  • url (str, optional, default is "") – The URL to send the POST command to.

  • json (Optional[dict]) – Not a real JSON object, but a Python dictionary that can be serialized to JSON.

  • files (Optional[dict]) – A Python dictionary of files, can be used for multipart uploads.

  • data (Optional[Dict[str, Any]]) – Payload to send with request. See requests post function documentation for more information.

  • expected_response (int, optional, default is 200) – The expected response from the endpoint.

  • kvargs – Additional key-value pair arguments passed on to the request.

Returns:

res – The result from the POST command.

Return type:

dict

See also

requests.request

put(url: str, data=None, **kwargs) Response

Use the session to issue a PUT.

Parameters:
  • url (str) – The URL to perform the PUT request.

  • data (Optional[Dict[str, Any]]) – Payload to send with request. See requests put function documentation for more details.

Returns:

res – The response object from requests.

Return type:

requests.Response

strangeworks.core.client.transport module

transport.py.

class strangeworks.core.client.transport.StrangeworksTransport(api_key: str, url: str, authenticator: Callable[[str], str], auth_token: str | None = None, headers: Dict[str, str] | None = None, timeout: int | None = None, retries: int = 0, **kvargs)

Bases: RequestsHTTPTransport

Transport layer with automatic token refresh.

connect()

Set up a session object.

Creates a session object for the transport to use and configures retries and re-authentication.

strangeworks.core.client.workspace module

workspace.py.

class strangeworks.core.client.workspace.Workspace(slug: str, is_disabled: bool, id: str | None, name: str | None = None)

Bases: object

Represents a Strangeworks user workspace.

static from_dict(obj: Dict[str, Any])

Generate a Workspace object from dictionary.

id: str | None
is_disabled: bool
name: str | None = None
slug: str
strangeworks.core.client.workspace.get(client: SDKAPI) Workspace

Return Workspace object.

Module contents

__init__.py.