AitoClient

class aito.sdk.aito_client.AitoClient(instance_url: str, api_key: str, check_credentials: bool = True)

Bases: object

A versatile client for your Aito Database Instance

async_requests(methods: List[str], endpoints: List[str], queries: List[Union[List, Dict]], batch_size: int = 10) → List[Dict]

async multiple requests

This method is useful when sending a batch of requests, for example, when sending a batch of predict requests.

Parameters
  • methods (List[str]) – list of request methods

  • endpoints (List[str]) – list of request endpoints

  • queries (List[Dict]) – list of request queries

  • batch_size (int) – the number of queries to be sent per batch

Returns

list of request response or exception if a request did not succeed

Return type

List[Dict]

check_table_exists(table_name: str) → bool

check if a table exists in the instance

Parameters

table_name (str) – the name of the table

Returns

True if the table exists

Return type

bool

create_database(database_schema: Dict) → Dict

create database with the given database schema API doc

Parameters

database_schema (Dict) – Aito database schema

Returns

the database schema

Return type

Dict

create_job(job_endpoint: str, query: Union[List, Dict]) → Dict

Create a job for queries that take longer than 30 seconds to run

API doc :param job_endpoint: job endpoint :type job_endpoint: str :param query: the query for the endpoint :type query: Union[List, Dict] :return: job information :rtype: Dict

create_table(table_name: str, table_schema: Dict) → Dict

create a table with the given table schema API doc

update the table if the table already exists and does not contain any data

Parameters
  • table_name (str) – the name of the table

  • table_schema (Dict) – Aito table schema

Returns

the table schema

Return type

Dict

delete_database() → Dict

delete the whole database API doc

Returns

deleted tables

Return type

Dict

delete_table(table_name: str) → Dict

delete a table API doc

Parameters

table_name (str) – the name of the table

Returns

deleted table

Return type

Dict

download_table(table_name: str, output_folder: os.PathLike, file_name: str = None, batch_size: int = 5000, gzip_output: bool = False)

download a table to a NDJSON file or a gzipped NDJSON file

Parameters
  • table_name (str) – the name of the table

  • output_folder (PathLike) – the folder where the output file is written to

  • batch_size (int) – the number of entries to be downloaded at once, defaults to 5000

  • gzip_output (bool) – gzip the output file, defaults to False

Parm file_name

the name of the output file, defaults to None in which the table name is used the file name

get_database_schema() → Dict

get the schema of the database API doc

Returns

Aito database schema

Return type

Dict

get_existing_tables() → List[str]

get a list of existing tables in the instance

Returns

list of the names of existing tables

Return type

List[str]

get_job_result(job_id: str) → Dict

Get the result of a job with the given id

API doc :param job_id: the id of the job :type job_id: str :return: the job result :rtype: Dict

get_job_status(job_id: str) → Dict

Get the status of a job with the given id

API doc :param job_id: the id of the job :type job_id: str :return: job status :rtype: Dict

get_table_schema(table_name: str) → Dict

get a table schema

Parameters

table_name (str) – the name of the table

Returns

the table schema

Return type

Dict

get_table_size(table_name: str) → int

return number of entries in a table

Parameters

table_name (str) – the name of the table

Returns

the number of entries in the table

Return type

int

get_version() → Dict

get the aito instance version

Returns

version information in json format

Return type

Dict

job_request(job_endpoint: str, query: Union[Dict, List] = None, polling_time: int = 10) → Dict

Make a request to an Aito API endpoint using job

This method should be used for requests that take longer than 30 seconds, e.g: evaluate

Parameters
  • job_endpoint (str) – job end point

  • query (Union[Dict, List], optional) – an Aito query, defaults to None

  • polling_time (int) – polling wait time, defaults to 10

Raises

RequestError – an error occurred during the execution of the job

Returns

request JSON content

Return type

Dict

optimize_table(table_name)
query_all_entries(table_name: str, batch_size: int = 5000) → List[Dict]

query all entries in a table

Parameters
  • table_name (str) – the name of the table

  • batch_size (int) – the number of entries to be queried at once

Returns

list of all entries in the table

Return type

List[Dict]

query_entries(table_name: str, offset: int = 0, limit: int = 10) → Dict

query entries of a table API doc

use offset and limit for pagination

Parameters
  • table_name (str) – the name of the table

  • offset (int, optional) – offset, defaults to 0

  • limit (int, optional) – limit, defaults to 10

Returns

the table entries

Return type

Dict

request(method: str, endpoint: str, query: Union[Dict, List] = None) → Dict

Make a request to an Aito API endpoint

Parameters
  • method (str) – request method

  • endpoint (str) – an Aito API endpoint

  • query (Union[Dict, List], optional) – an Aito query, defaults to None

Raises

RequestError – an error occurred during the execution of the request

Returns

request JSON content

Return type

Dict

upload_binary_file(table_name: str, binary_file: BinaryIO, optimize_on_finished: bool = True, polling_time: int = 10)

upload a binary file object to a table API doc

Parameters
Raises

RequestError – an error occurred during the upload of the file to S3

upload_entries(table_name: str, entries: Iterator[Dict], batch_size: int = 1000, optimize_on_finished: bool = True)

populate a list of table entries by batches of batch_size :param table_name: the name of the table :type table_name: str :param entries: list of the table entries :type entries: Iterator[Dict] :param batch_size: the batch size, defaults to 1000 :type batch_size: int, optional :param optimize_on_finished: `optimize https://aito.ai/docs/api/#post-api-v1-data-table-optimize`__ the table on finished, defaults to True :type optimize_on_finished: bool

upload_entries_by_batches(table_name: str, entries: Iterator[Dict], batch_size: int = 1000, optimize_on_finished: bool = True)
upload_file(table_name: str, file_path: os.PathLike, optimize_on_finished: bool = True, polling_time: int = 10)

upload a file to a table API doc

Parameters
Raises
  • BaseError – incorrect file extension, should be .ndjson.gz

  • RequestError – an error occurred during the upload of the file to S3

exception aito.sdk.aito_client.BaseError(message)

Bases: Exception

exception aito.sdk.aito_client.RequestError(method: str, endpoint: str, query: Union[List, Dict], error: Exception)

Bases: aito.sdk.aito_client.BaseError