# Utilize the PlanQK Service SDK for Local Development

This tutorial provides step-by-step guidance on how to create services, monitor their statuses, retrieve their results, and cancel their executions locally. To accomplish this objective, the tutorial utilizes the PlanQK Service SDK and PlanQK CLI.

Prerequisites: Ensure that Docker is installed and running properly. For detailed documentation, please refer to the following link: Docker Desktop (opens new window)

# Deploying the Services locally with the PlanQK CLI

To install the PlanQK CLI, you must install Node.js and the npm command line interface using either a Node version manager (opens new window) or a Node installer (opens new window).

Then install the PlanQK CLI globally using npm:

npm install -g @anaqor/planqk
1

Once the installation is complete, start by navigating to the directory where your project, which includes the service, is located.

cd my-project
1

Next, run the following command:

planqk serve
1

Once the SERVICE is up and running, you can access its API under http://localhost:8081/. For additional details regarding the planqk serve functionality, please refer to the documentation available here (opens new window).

# Accessing a Service with the PlanQK Service SDK

Supported operations are: creating, monitoring the status of the service, retrieving the execution result and cancelling the execution of the service.

Begin by installing the PlanQK Service SDK using pip.

pip install --upgrade planqk-service-sdk
1

Replace the placeholders your_consumer_key and your_secret_key in the code snippet below with the credentials provided in one of your platform applications. Additionally, configure the service_endpoint to the URL where planqk sere operates. In the example below, the server is operating on the default URL.

from planqk.service.client import PlanqkServiceClient

# Your consumer key and secret
consumer_key = "your_consumer_key"
consumer_secret = "your_consumer_secret"

# Service endpoint
service_endpoint = "http://localhost:8081/"

# Initialize the client
client = PlanqkServiceClient(service_endpoint, consumer_key, consumer_secret)
1
2
3
4
5
6
7
8
9
10
11

You can initiate executions as illustrated in the following example:

data = {"dataValue" : ["abc", "dce"]}
params = {"paramsValue" : ["abc", "dce"]}

# start execution
job = client.start_execution(data=data, params=params)
1
2
3
4
5

To check the status of an execution, utilize the following code snippet:

# get execution status
status = client.get_status(job.id)
1
2

Retrieve the result of an execution with the following example:

# get execution result
result = client.get_result(job.id)
1
2

Lastly, to cancel an execution, follow this example:

# get execution result
client.cancel_execution(job.id)
1
2