Scala client for accessing Algorithmia’s algorithm marketplace and data APIs
The Algorithmia scala client is published to Maven central and can be added as a dependency via:
Instantiate a client using your API Key:
- API key may be omitted only when making calls from algorithms running on the Algorithmia cluster
Now you are ready to call algorithms.
The following examples of calling algorithms are organized by type of input/output which vary between algorithms.
Note: a single algorithm may have different input and output types, or accept multiple types of input, so consult the algorithm’s description for usage examples specific to that algorithm.
Call an algorithm with text input by simply passing a string into its
If the algorithm output is text, call the
asString method on the response.
Call an algorithm with JSON input by simply passing in a type that can be serialized to JSON,
including most plain old java objects, scala classes, and collection types.
If the algorithm output is JSON, call the
as method on the response with the type that it should be deserialized into:
Alternatively, you may work with raw JSON input by calling
and raw JSON output by calling
asJsonString on the response:
Call an algorithm with binary input by passing a byte array into the
If the algorithm response is binary data, then call the
asBytes method on the response to obtain the raw byte array.
API errors will result in the call to
Errors that occur durring algorithm execution will result in
AlgorithmException when attempting to read the response.
The client exposes options that can configure algorithm requests. This includes support for changing the timeout or indicating that the API should include stdout in the response.:
withStdout(true) is ignored if you do not have access to the algorithm source.
Working with Data
The Algorithmia scala client also provides a way to manage both Algorithmia hosted data and data from Dropbox or S3 accounts that you’ve connected to you Algorithmia account.
This client provides a
DataFile type (generally created by
DataDir type (generally created by
client.dir(uri)) that provide
methods for managing your data.
Create directories by instantiating a
DataDirectory object and calling
Upload files to a directory
Upload files by calling
put on a
DataFile object, or by calling
putFile on a
Download contents of file
Download files by calling
getFile on a DataFile object:
Delete files and directories
Delete files and directories by calling
delete on their respective
DataDirectories take an optional
force parameter that indicates whether the directory should be deleted
if it contains files or other directories.
List directory contents
Iterate over the contents of a directory using the iterator returned by calling
dirs on a
Manage directory permissions
Directory permissions may be set when creating a directory, or may be updated on already existing directories.