strangeworks package

Subpackages

Submodules

strangeworks.sw_client module

client.py.

class strangeworks.sw_client.SWClient(cfg: ConfigSource, headers: Dict[str, str] | None = None, rest_client: StrangeworksRestClient | None = None, **kwargs)

Bases: object

Strangeworks client object.

add_tags(job_slug: str, tags: List[str]) List[str]

Add tags to a job.

Parameters:
  • job_slug (str) – The slug of the job.

  • tags (List[str]) – The tags to add to the job.

Returns:

The tags linked to the job.

Return type:

List[str]

authenticate(api_key: str | None = None, url: str | None = None, profile: str | None = None, store_credentials: bool = True, overwrite: bool = False, **kwargs) None

Authenticate with Strangeworks.

Obtains an authorization token from the platform using the api_key. The auth token is used to make calls to the platform. Access to platform interfaces are initialized.

Parameters:
  • api_key (Optional[str]) – The API key.

  • url (Optional[str]) – The base URL to the Strangeworks API.

  • profile (Optional[str]) – The profile name to use for configuration.

  • store_credentials (bool) – Indicates whether credentials (api key an url) should be saved. Defaults to True.

  • overwrite (bool) – Indicates whether to overwrite credentials if they already exist. Defaults to False.

  • **kwargs – Additional arguments.

download_job_files(file_paths: str | list, resource_slugs: List[str] | None = None, product_slugs: List[str] | None = None, statuses: List[str] | None = None) List[File]
download_job_files(file_paths: str, resource_slugs: List[str] | None = None, product_slugs: List[str] | None = None, statuses: List[str] | None = None) List[File]
download_job_files(file_paths: list, resource_slugs: List[str] | None = None, product_slugs: List[str] | None = None, statuses: List[str] | None = None) List[File]

Download files associated with a job.

Parameters:

file_paths (Union[str, list]) – either the job slug (str) or a list of URLs associated with a Job object.

Return type:

A List of File objects.

execute(res: Resource, payload: Dict[str, Any] | None = None, endpoint: str | None = None)

Execute a job request.

Parameters:
  • res (Resource) – the resource that has the function to call.

  • payload (Optiona;[Dict[str, Any]]) – the payload to send with the request.

  • endpoint – additional endpoint to append to the proxy path for the resource.

execute_get(product_slug: str, endpoint: str | None = None)

Execute GET.

Parameters:
  • product_slug (str) – string used to identify a product entry on the platform.

  • endpoint (str | None = None) – additional path that denotes a service/product endpoint.

Returns:

  • Result of the request, typically a JSON serializable object like a

  • dictionary.

execute_post(product_slug: str, payload: Dict[str, Any] | None = None, json: dict | None = None, data: any | None = None, endpoint: str | None = None)

Execute a job request.

Parameters:
  • product_slug (str) – string used to identify a product entry on the platform.

  • payload – same as json

  • json – A JSON serializable Python object to send in the body of the Request.

  • data – Dictionary, list of tuples, bytes, or file-like object to send in the body of the Request. Typically a string.

  • endpoint (str | None = None) – additional path that denotes a service/product endpoint.

Return type:

Result of the request, typically a dictionary.

get_backend(backend_slug: str) Backend

Return a single backend by the slug.

Replaces the deprecated BackendsService.

get_backends(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]

Return a list of backends available based on the filters provided.

Replaces the deprecated BackendsService.

get_error_messages(job_slug: str) Dict[str, List[File]]
get_resource_for_product(product_slug: str) Resource

Get resource to use when using product.

If the user has a resource allready configured and that resource still exists, that resource will be returned. If the user-configured resource no longer exists, an error will be raised.

If user does not have a resource identified for the product and there is only a single resouce for the product available in the users workspace, that resource will be returned.

If there are multiple resources for the given product slug and the user hasn’t already selected one, they will be asked to do so.

If there are no resources configured for the product slug, an error will be raised asking the user to create one.

Parameters:

product_slug (str) – product identifier.

Returns:

a resource object which maps to the product.

Return type:

Resource

Raises:

:StrangeworksError – if no resource is found or there are multiple resource and none selected.

get_sdk_api() SDKAPI

Return SDK API instance.

jobs(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, tag_operator: TagOperator | None = None) List[Job] | None

Retrieve list of jobs associated with the current workspace account.

Parameters:
  • slug (Optional[str] = None) – Identifier for a specific job. Defaults to None.

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

  • product_slugs (Optional[List[str]]) – List of product identifiers. Only jobs whose product slugs match will be returned. Defaults to None.

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

  • tags (Optional[List[str]]) – List of tags to filter the jobs by. Defaults to None.

  • tag_operator (Optional[TagOperator]) – The logical operator to use for the tags. Can be either “AND” or “OR”. Defaults to None, treating the tags list as an OR operation if multiple tags are provided.

Returns:

List of jobs or None if there are no jobs that match selection criteria.

Return type:

Optional[List[Job]]

resources(slug: str | None = None) List[Resource] | None

Retrieve list of resources that are available for this workspace account.

Parameters:

slug (Optional[str]) – Identifier for a specific resource. Defaults to None.

Returns:

List of resources for the current workspace account or None if no resources have been created.

Return type:

Optional[List[Resource]]

set_resource_for_product(resource_slug: str, product_slug: str) None

Set which resource to use for a given product.

Users can have multiple resources set up for the same product. When this is the case, they can set which resource to use with this call.

Parameters:
  • resource (str) – Resource identifier (currently the slug).

  • product_slug

    str

    product identifier.

upload_file(file_path: str) File

Upload a file to strangeworks.

File.url is how you can download the file.

raises StrangeworksError if any issues arise while attempting to upload the file.

workspace_info() Workspace

Retrieve information about the current workspace.

class strangeworks.sw_client.TagOperator(value)

Bases: Enum

Logical operators for tags.

AND = 'AND'
OR = 'OR'

strangeworks.utils module

utils.py.

strangeworks.utils.is_empty_str(s: str) bool

Check if string is empty.

A string is considered to be empty if any one of the following conditions are true:
  • it is set to None or

  • consists exclusively of spaces

  • is equal to “”

Module contents

Strangeworks SDK.