lightly.api

The lightly.api module provides access to the Lightly web-app.

.api_workflow_client

class lightly.api.api_workflow_client.ApiWorkflowClient(token: str, dataset_id: str = None, embedding_id: str = None)

Provides a uniform interface to communicate with the api

The APIWorkflowClient is used to communicaate with the Lightly API. The client can run also more complex workflows which include multiple API calls at once.

The client can be used in combination with the active learning agent.

Args:
token:

the token of the user, provided in webapp

dataset_id:

the id of the dataset, provided in webapp. If it is not set, but used by a workflow, the last modfied dataset is taken by default.

embedding_id:

the id of the embedding to use. If it is not set, but used by a workflow, the newest embedding is taken by default

property dataset_id

The current dataset_id.

If the dataset_id is set, it is returned. If it is not set, then the dataset_id of the last modified dataset is selected.

property filenames_on_server

The list of the filenames in the dataset.

upload_file_with_signed_url(file: io.IOBase, signed_write_url: str, max_backoff: int = 32, max_retries: int = 5) → requests.models.Response

Uploads a file to a url via a put request.

Args:
file:

The file to upload.

signed_write_url:

The url to upload the file to. As no authorization is used, the url must be a signed write url.

max_backoff:

Maximal backoff before retrying.

max_retries:

Maximum number of retries before timing out.

Returns:

The response of the put request, usually a 200 for the success case.

.utils

Communication Utility

lightly.api.utils.PIL_to_bytes(img, ext: str = 'png', quality: int = None)

Return the PIL image as byte stream. Useful to send image via requests.

lightly.api.utils.check_filename(basename)

Checks the length of the filename.

Args:
basename:

Basename of the file.

lightly.api.utils.getenv(key: str, default: str)

Return the value of the environment variable key if it exists, or default if it doesn’t.

lightly.api.utils.retry(func, *args, **kwargs)

Repeats a function until it completes successfully or fails too often.

Args:
func:

The function call to repeat.

args:

The arguments which are passed to the function.

kwargs:

Key-word arguments which are passed to the function.

Returns:

What func returns.

Exceptions:

RuntimeError when number of retries has been exceeded.