Algorithmia Blog

Getting Started with the Algorithmia Command Line Interface (CLI)

These instructions are out-of-date. Please See https://algorithmia.com/developers/clients/cli/ instead.

Algorithmia has released a command line interface (CLI)! This new, cross-platform tool allows you to use the command line to call more than 1,600 algorithms from the Algorithmia API.

The official docs can be found in the README on GitHub, but we’ll do a quick walkthrough to get you up and running.

Installation:

Setting up the Algorithmia CLI is easy.

OSX

Download and extract the OSX tarball with this cURL command:

$ curl -L https://github.com/algorithmiaio/algorithmia-cli/releases/download/v1.0.0-beta.2/algorithmia_osx.tar.gz | tar -xz

We recommend putting it within your PATH with the following:

$ sudo mv algo /usr/local/bin/

Windows (64-bit)

First, install OpenSSL for Windows.

Next, download and extract the Windows zip file. We recommend putting it within your PATH.

Looking for instructions for Debian/Ubuntu or Arch installs? Find them on the official README.

Configure the CLI:

Before we can start making calls to the APIs, first we need configure our authentication. Run the command:

$ algo auth

You’ll be prompted to input your API key for a default profile. If you’d like to create more than one profile, simply run algo auth [<profile>] for the same interactive prompt. For more information, see the auth command help with algo auth --help.

Check that your profile is configured by running algo ls.

Usage:

Now that we’re set up, let’s try executing some algorithms! We’re going to start with something simple, the Factor algorithm that takes in integer and returns its prime factors. You can find the details about this algorithm on the description page.

$ algo run kenny/factor -d 19635
[3,5,7,11,17]

Here we see the basic syntax: algo run, followed by the algorithm’s username and algorithm name (kenny/factor), the data options, and finally the input. The response we got back was just the result of the algorithm, but we can also add the option --response-body to see the full JSON response:

$ algo run kenny/factor -d 19635 --response-body
{"result":[3,5,7,11,17],"metadata":{"content_type":"json","duration":0.001427314}}

Run algo run --help to see more command options, including the data input and output options.

The Algorithmia CLI is also great for interacting with the Algorithmia API. You can use the CLI to create and manage your data directories. Let’s say you want to create a new data directory and upload some files-it’s easy with the CLI.

First, create a new data directory:

$ algo mkdir .my/favoritepics

Created directory data://.my/favoritepics

Copy a file from your local directory to the new data directory:

$ algo cp puppies.png data://.my/favoritepics

Uploaded data://.my/favoritepics/puppies.png

When you’ve finished uploading, check that everything you expect is in your data directory:

$ algo ls .my/favoritepics

puppies.png kittens.jpg baby_turtles.jpg

Example:

Algorithmia CLI use of opencv/SmartThumbnail

Help:

Run algo --help for additional usage information and to learn about other command options. Be sure to check out the official README for even more detailed instructions on using the Algorithmia CLI and new release updates!