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.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, file_size_bytes: int | 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), 'file_size_bytes': FieldInfo(annotation=Union[int, NoneType], required=False, default=None, alias=AliasChoices(choices=['metaSizeBytes', 'file_size_bytes']), 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] objects.

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, tags: List[str] | 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), 'tags': FieldInfo(annotation=Union[List[str], NoneType], required=False, default=None)}

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

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.jobs.tag(client: SDKAPI, workspace_slug: str, job_slug: str, tags: List[str]) List[str]

Add tags to a 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.