Quick Start Python SDK

Install a SDK

Now that you have your personal token, you can use one of Qarnot's SDKs to use the cloud platform. Here is a simple example of Hello World using the Python SDK.

We recommend you to set up a Python virtual environment with virtualenv:

$ python3 -m venv venv

Then, each time you want to use your virtual environment you have to activate it:

$ . venv/bin/activate

Finally you have to install in your environment the Qarnot SDK:

$ pip install qarnot

You are now ready to use Qarnot's Python SDK.

For other languages or more in-depth examples, refer to the Launching a computation with one of our SDKs section or to each SDK documentation: Python, C#, Node.js.

Run a Hello World

Create a helloworld.py file with the following code sample. Beware of replacing xxxx_mytoken_xxxx with your actual token or the path to your configuration file.

import qarnot
conn = qarnot.connection.Connection(client_token="<<<MY_SECRET_TOKEN>>>")
task = conn.create_task('hello world', 'docker-batch', 4)
task.constants['DOCKER_CMD'] = 'echo hello world from node ${INSTANCE_ID}!'
task.run()
print(task.stdout())

Then launch the script

$ python helloworld.py
The created task is named 'hello world' and is a 'docker-batch' application of four instances. The command echo hello world! will be executed on four compute node in the cloud. Not locally.

What happened? After opening a connection using your API token, you created a task of 4 instances using the docker-batch profile. Each one of them starts a Docker container using the INSTANCE_ID parameter to output a string:

1> hello world from node 1!
3> hello world from node 3!
0> hello world from node 0!
2> hello world from node 2!
The .run() method performs a blocking call. In the non-blocking version, you can use .freshstdout() and .freshstderr() to display new output only.
You can use .stderr() to display task standard error.

Congratulations, you have run your first task on Qarnot's cloud platform! Deep dive into this documentation to discover more functionalities and use cases.

Related Article

For more information on Launching tasks please consult the following articles