Hello World
In this first example, we will use our Python SDK, PymoniK, to write our first ArmoniK-flavored Hello World program. We also provide SDKs in Java, C#, and C++ for your convenience.
This guide will walk you through the steps to get your first distributed function up and running using PymoniK.
Step 0: Prerequisites
ArmoniK cluster
In order to run this example, we assume that you have access to an ArmoniK cluster configured with a partition named pymonik, if you completed the local deployment from the quick section then you are good to go (by default it deploys ArmoniK with such a partition). Remember from that section, you should have the following information available:
Apply complete! Resources: 125 added, 0 changed, 0 destroyed.
Outputs:
armonik = {
"admin_app_url" = "http://10.100.1.166:5000/admin"
"chaos_mesh_url" = null
"control_plane_url" = "http://10.100.1.166:5001"
"grafana_url" = "http://10.100.1.166:5000/grafana/"
"seq_web_url" = "http://10.100.1.166:5000/seq/"
}
OUTPUT FILE: /home/ubuntu/ArmoniK/infrastructure/quick-deploy/localhost/generated/armonik-output.json
Run to point your ArmoniK CLI to this deployment:
------------------------------
export AKCONFIG=/home/ubuntu/ArmoniK/infrastructure/quick-deploy/localhost/generated/armonik-cli.yaml
uv package manager
The worker deployed in the pymonik partition uses python 3.10.12, in order to produce client code compatible with it, we will employ
the uv package manager, which allows to create a virtual environment targeting the version of python of our choice. If uv is not yet available
in your system, you can install it by following its official documentation.
Step 1: Install PymoniK
Ensure you have the PymoniK framework installed in your Python environment. First we will create a new project and specify
that it should use the version 3.10.12 of python
mkdir hello_pymonik && cd hello_pymonik
uv init --python 3.10.12
Next, we can install the pymonik package:
uv add pymonik
Step 2: Import Necessary Modules
Now you can edit a new your_script_name.py file with the editor of your choice and import the required modules to work with PymoniK.
You’ll need the Pymonik context manager and the task decorator.
from pymonik import Pymonik, task
Step 3: Define Your Distributed Function
Create your distributed function using the @task decorator. In this case, we will create a simple function that just returns “hello world”.
@task
def hello_worlder():
return "hello world"
Step 4: Invoke Your Function
To run your hello_worlder function on the ArmoniK cluster, wrap your invocation in a with PymoniK() context. Call the invoke() method and wait for the result.
with PymoniK():
print(hello_worlder.invoke().wait().get())
Step 5: Run the Complete Program
Combine all of the above steps:
1from pymonik import PymoniK, task
2
3@task
4def hello_worlder():
5 return "hello world"
6
7if __name__ == "__main__":
8 with PymoniK(endpoint="http://10.100.1.166:5001"):
9 print(hello_worlder.invoke().wait().get())
The endpoint parameter in line 8 should match the control_plane_url of your ArmoniK cluster. Alternatively, you could omit this parameter and
import export the AKCONFIG variable to our current environment before launching the example.
Step 6: Execute the Program
Run your script from the command line:
uv run your_script_name.py
You should see the output:
Session 23cef225-3a06-4b11-8d2f-ff50856ac7cd has been created
An after a few seconds, it should complete to:
Session 23cef225-3a06-4b11-8d2f-ff50856ac7cd has been created
hello world
Session 23cef225-3a06-4b11-8d2f-ff50856ac7cd has been closed
Congratulations! You have successfully set up your first distributed function using PymoniK.