Appearance
Interacting with the PLANQK Platform Using the API SDK
The PLANQK API SDK allows you to interact with the PLANQK Platform. It provides a convenient way to manage data pools, upload and download files, and perform other operations on the platform.
There are SDKs available for both Python and TypeScript, making it easy to integrate with your applications. The TypeScript SDK can be found at @planqk/api-sdk
, while the Python SDK is available as planqk-api-sdk
.
Installation
Install the PLANQK API SDK using pip
:
bash
pip install --upgrade planqk-api-sdk
Authentication
To use the SDK, you need to authenticate with your personal access token, which can be found on the PLANQK welcome page or generated in the settings.
Set your access token in one of the following ways:
- Environment Variable: Set the
PLANQK_ACCESS_TOKEN
environment variable. The SDK will automatically use it. - Directly: Pass the token when creating the
PlanqkApiClient
.
Using the SDK
Create a PlanqkApiClient
instance to interact with the API:
python
from planqk.api.client import PlanqkApiClient
# Create a client (authenticates via environment variable)
client = PlanqkApiClient()
# Or, pass the token directly
# client = PlanqkApiClient(access_token="YOUR_PERSONAL_ACCESS_TOKEN")
Data Pools
The data_pools
property provides access to data pool operations.
List Data Pools
Retrieve a list of all your data pools:
python
data_pools = client.data_pools.get_data_pools()
for data_pool in data_pools:
print(f"ID: {data_pool.id}, Name: {data_pool.name}")
Create a Data Pool
Create a new data pool:
python
new_data_pool = client.data_pools.create_data_pool(name="My New Data Pool")
print(f"Created data pool with ID: {new_data_pool.id}")
Get a Specific Data Pool
Retrieve a data pool by its ID:
python
data_pool_id = "YOUR_DATA_POOL_ID"
data_pool = client.data_pools.get_data_pool(id=data_pool_id)
print(f"Data Pool Name: {data_pool.name}")
Update a Data Pool
Update a data pool's information:
python
updated_data_pool = client.data_pools.update_data_pool(
id=data_pool_id,
name="Updated Data Pool Name",
description="A new description."
)
print(f"Updated data pool: {updated_data_pool.name}")
Delete a Data Pool
Delete a data pool by its ID:
python
client.data_pools.delete_data_pool(id=data_pool_id)
print("Data pool deleted.")
Data Pool Files
Manage files within a specific data pool.
List Files in a Data Pool
Get a list of all files in a data pool:
python
files = client.data_pools.get_data_pool_files(id=data_pool_id)
for file in files:
print(f"File ID: {file.id}, Name: {file.file_name}")
Add a File to a Data Pool
Upload a file to a data pool:
python
from planqk.api.sdk.core import File
with open("my_file.txt", "rb") as f:
added_file = client.data_pools.add_data_pool_file(
id=data_pool_id,
file=File(file=f, filename="my_file.txt")
)
print(f"Added file with ID: {added_file.id}")
Download a File from a Data Pool
Download a file's content:
python
file_id = "YOUR_FILE_ID"
file_content_stream = client.data_pools.get_data_pool_file(id=data_pool_id, file_id=file_id)
with open("downloaded_file.txt", "wb") as f:
for chunk in file_content_stream:
f.write(chunk)
print("File downloaded.")
Delete a File from a Data Pool
Delete a file from a data pool:
python
client.data_pools.delete_data_pool_file(id=data_pool_id, file_id=file_id)
print("File deleted.")
Supported Operations
PlanqkApiClient
Property | Description |
---|---|
data_pools | Accesses the DataPoolsClient . |
DataPoolsClient
Method | Description |
---|---|
get_data_pools | Retrieves a list of all data pools. |
create_data_pool | Creates a new data pool. |
get_data_pool | Retrieves a specific data pool by ID. |
update_data_pool | Updates a data pool's information. |
delete_data_pool | Deletes a data pool by ID. |
get_data_pool_files | Retrieves a list of files in a data pool. |
add_data_pool_file | Adds a file to a data pool. |
get_data_pool_file | Downloads a file from a data pool. |
delete_data_pool_file | Deletes a file from a data pool. |