Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
232 lines (196 sloc) 8.05 KB

Aito Command Line Interface

DISCLAIMER: Aito Command Line Interface repository is experimental code that we are already using ourselves. It might be a bit rough on the edges and is not yet ready for production grade release. We are constantly developing it and changes are likely. Feel free to use, and share any feedback with us.

The Aito CLI tool aims to help you get upload your data to your Aito instance as fast as possible.

Installation

To install with pip, run: pip install aitoai

To install from source, first clone the repository and then run: python setup.py install

Aito supports integration with your SQL database. To enable this feature, please follow the instructions here

Introduction

To get started:

aito -h
usage: aito [-h] <action> ...

optional arguments:
  -h, --help          show this help message and exit

action:
  action to perform

  <action>
    infer-table-schema
                      infer an Aito table schema from a file
    convert           convert a file into ndjson|json format
    database          perform operations with your Aito database instance

Supported actions:

Quick guide to upload the data

Quickly upload a file to your database instance by following these steps:

  • Set up the credentials
  • Run:
    aito database quick-add-table path/to/dataFile
    To see help:
    aito database quick-add-table -h

Step-by-step instructions to upload the data

  • Infer an Aito table schema from your data file:

    aito infer-table-schema <file-format> path/to/yourFile path/to/inferedSchema.json

    Examine the inferred schema and change if necessary. E.g: An 'id' column should be of type 'String' but is inferred as 'Int'.

    You can skip this step if you already have an existing table or a table schema.

  • Set up the credentials

  • Create a table with the created schema:

    aito database create-table <table-name> path/to/tableSchema

    You can skip this step if you want to upload the data to an existing table

  • Upload the data file to your database instance:

    aito database upload-file <table-name> path/to/dataFile

In-depth guide

Infer an Aito table schema from a file

  • To see help:
    aito infer-table-schema - h
  • By default, the command takes standard input and standard output. To redirect:
    aito infer-table-schema csv < path/to/myFile.csv > path/to/schemaFile.json
  • Infer table schema from a csv file
    aito infer-table-schema csv < path/to/myCSVFile.csv
    Infer table schema from a semicolon delimited csv file
    aito infer-table-schema csv -d ';' < path/to/myCSVFile.csv
    Infer table schema from a semicolon delimited comma decimal point csv file
    aito infer-table-schema csv -d ';' -p ',' < path/to/myCSVFile.csv
  • Infer table schema from an excel file:
    aito infer-table-schema excel path/to/myExcelFile.xlsx
    Infer table schema from a single sheet of an excel file
    aito infer-table-schema excel -o sheetName path/to/myExcelFile.xls
  • Infer table schema from a json file:
    aito infer-table-schema json path/to/myJsonFile.json
  • Infer table schema from a njson file:
    aito infer-table-schema ndjson path/to/myNdJsonFile.ndjson

Convert data to be uploaded into Aito

Aito takes JSON array of objects for Inserting multiple entries and a gzip compressed ndjson file for File upload.

  • To see help:
    aito convert -h
  • By default, the command takes standard input and standard output. To redirect:
    aito convert csv < path/to/myFile.csv > path/to/myConvertedFile.ndjson
  • Convert a csv file to ndjson format for file upload:
    aito convert csv path/to/myFile.csv > path/to/myConvertedFile.ndjson
  • Convert an excel file to JSON format for batch upload and infer a Aito table schema:
    aito convert excel path/to/myFile.xlsx > path/to/myConvertedFile.json
  • Convert a file and infer an Aito table schema on the way:
    aito convert csv -c path/to/myInferredTableSchema.json path/to/myFile.csv > path/to/myConvertedFile.ndjson
  • Convert a file into the desired format declared in a given Aito table schema (e.g: Id should be string instead of Int):
    aito convert csv -s path/to/desiredSchema.json path/to/myFile.csv > path/to/myConvertedFile.ndjson
    This is useful if you change the inferred schema and want to convert the data accordingly

Perform operations with your Aito database instance

Setting up the credentials

Performing operation with your Aito database instance always requires credentials. There are 3 ways to set up the credentials:

  • The most convinient way is to set up the following environment variables:

    AITO_INSTANCE_NAME=your-instance-name
    AITO_API_KEY=your-api-key
    

    You can now perform operations with:

    aito database <operation> ...
  • Using a dotenv (.env) file:

    Your .env file should contain environment variables as described above.

    You can set up the credentials using a dotenv file with the -e flag. For example:

    aito database -e path/to/myDotEnvFile.env <operation> ...
  • Using flags:

    You can set up the credentials using -i flag for the instance name, -k flag for the api key:

    aito database -i MY_AITO_INSTANCE_NAME -k MY_API_KEY <operation> ...

Some common operations

Tab Completion

The CLI supports tab completion using argcomplete

  • To activate global completion:
    activate-global-python-argcomplete

More instructions can be found here

  • If you choose not to use global completion:
    eval "$(register-python-argcomplete aito)"
    You might have to install python3-argcomplete:
    sudo apt install python3-argcomplete
You can’t perform that action at this time.