tensorbay.client.requests

Class Client and method multithread_upload.

Client can send POST, PUT, and GET requests to the TensorBay Dataset Open API.

multithread_upload() creates a multi-thread framework for uploading.

class tensorbay.client.requests.Client(access_key, url='')[source]

Bases: object

This class defines Client.

Client defines the client that saves the user and URL information and supplies basic call methods that will be used by derived clients, such as sending GET, PUT and POST requests to TensorBay Open API.

Parameters
  • access_key (str) – User’s access key.

  • url (str) – The URL of the graviti gas website.

Return type

None

static do(method, url, **kwargs)[source]

Send a request.

Parameters
  • method (str) – The method of the request.

  • url (str) – The URL of the request.

  • **kwargs – Extra keyword arguments to send in the GET request.

  • kwargs (Any) –

Returns

Response of the request.

Return type

requests.models.Response

open_api_do(method, section, dataset_id='', **kwargs)[source]

Send a request to the TensorBay Open API.

Parameters
  • method (str) – The method of the request.

  • section (str) – The section of the request.

  • dataset_id (str) – Dataset ID.

  • **kwargs – Extra keyword arguments to send in the POST request.

  • kwargs (Any) –

Raises

ResponseError – When the status code OpenAPI returns is unexpected.

Returns

Response of the request.

Return type

requests.models.Response

tensorbay.client.requests.multithread_upload(function, arguments, *, callback=None, jobs=1, pbar)[source]

Multi-thread upload framework.

Parameters
  • function (Callable[[tensorbay.client.requests._T], Optional[tensorbay.client.requests._R]]) – The upload function.

  • arguments (Iterable[tensorbay.client.requests._T]) – The arguments of the upload function.

  • callback (Optional[Callable[[Tuple[tensorbay.client.requests._R, ...]], None]]) – The callback function.

  • jobs (int) – The number of the max workers in multi-thread uploading procession.

  • pbar (tensorbay.utility.requests.Tqdm) – The Tqdm instance for showing the upload process bar.

Return type

None

class tensorbay.client.requests.MultiCallbackTask(*, function, callback, size=50)[source]

Bases: Generic[tensorbay.client.requests._T, tensorbay.client.requests._R]

A class for callbacking in multi-thread work.

Parameters
  • function – The function of a single thread.

  • callback – The callback function.

  • size – The size of the task queue to send a callback.

work(argument)[source]

Do the work of a single thread.

Parameters

argument (tensorbay.client.requests._T) – The argument of the function.

Return type

None

last_callback()[source]

Send the last callback when all works have been done.

Return type

None