Every Algorithm is an API Endpoint: it has a unique URL which accepts and returns JSON. While you could chose to assemble and send raw JSON (we'll talk a bit about this in the next lesson), there's an easier way: the Algorithmia Client.
Installing the Client
The Client is simply a library, implemented in most popular programming languages, which provides a standardized, ergonomic way of calling any Algorithm. Installation is simple and lightweight -- e.g. "pip install Algorithmia" in Python, or adding the script https://algorithmia.com/v1/clients/js/algorithmia-0.2.0.js in browser-side JS. To find your language-specific installation instructions, either find an Algorithm and scroll down to its "Install and Use" section, or take a look at the language-specific client guides.
Using the Client
The Client's syntax is nearly identical across all languages, with only a few minor differences (for example, the JS client necessarily uses callbacks). Using Python as an example, the main components are:
- import Algorithmia - includes the Algorithmia library.
- client = Algorithmia.client("YOUR_API_KEY") - create a Client instance, using one of the keys from the API Keys tab of your account page (more info: Your Account).
- algo = client.algo(nlp/SentimentAnalysis/1.0.5') - get ready to call version 1.0.5 of the Algorithm "nlp/SentimentAnalysis". If a version number is omitted, the most recently published version of the Algorithm will be used.
- (optional) algo.set_options(timeout=300) - set any optional parameters for how this call should be made (in this case, we're setting the timeout to 300 seconds, which is the default anyway).
- algo.pipe(input) - run the Algorithm, sending it appropriate input. This might be text, a number, an array, or even a dictionary -- all depending on what the specific Algorithm you're running expects. See the Algorithm's Page for a sample input, and check the "docs" tab of that page for more examples. More info about this in the next section.
- do whatever you want with the result returned by algo.pipe() - but start by printing it, so you can see how the results are structured (these are also documented on each Algorithm's Page).