Spartacloud Python API
Project description
Spartacloud
This API provides many services you can use from Spartacloud
Installation
API
Install the package via pip with code below:
pip install spartacloud
To Upgrade:
pip install --upgrade spartacloud
Application
There are two types of Spartacloud image your can pull:
- Master node
- Developer node
Master nodes are special instances that should be reserved for administrator. They can control the full cluster with unlimited access.
Developer nodes are instances reserved for developers or business teams. They can interact with the cluster and enjoy Spartacloud capabilities, such as:
- Deploying remote jobs
- Terminal access control
- Shared resources
- Private git server
- Private container registry
- Managing internal applications
- Xserver
- PlotDB
- SpartaQuant application
- Default applications
Authentication
- First, you must pull the docker image on your server and create an account
- Go the cluster page, in the API section and generate an API key
- Import the spartacloud module
from spartacloud.spartacloud_api import Spartacloud
spartacloud_obj = Spartacloud(api_key)
Examples
Some examples to start with the Spartacloud API:
Cluster information
- Get list of nodes
from spartacloud.spartacloud_api import Spartacloud
spartacloud_obj = Spartacloud(api_key)
spartacloud_obj.get_computer_nodes()
- Cluster metrics
from spartacloud.spartacloud_api import Spartacloud
spartacloud_obj = Spartacloud(api_key)
spartacloud_obj.get_metrics_cluster()
- Cluster status
from spartacloud.spartacloud_api import Spartacloud
spartacloud_obj = Spartacloud(api_key)
spartacloud_obj.get_status_cluster()
- Cluster CPU usage
from spartacloud.spartacloud_api import Spartacloud
spartacloud_obj = Spartacloud(api_key)
spartacloud_obj.get_cpu_cluster()
- Cluster MEM usage
from spartacloud.spartacloud_api import Spartacloud
spartacloud_obj = Spartacloud(api_key)
spartacloud_obj.get_mem_cluster()
- Cluster disk usage
from spartacloud.spartacloud_api import Spartacloud
spartacloud_obj = Spartacloud(api_key)
spartacloud_obj.get_disk_cluster()
Distributed Jobs
- Distribute a job remotely
from spartacloud.spartacloud_api import Spartacloud
spartacloud_obj = Spartacloud(api_key)
data_store_cluster_obj = spartacloud_obj.distribute_job(
job_cmd,
job_name=None,
target_node=None,
target_cpu=None,
target_mem=None,
store_stdout=True,
b_rerun=False
)
- Get job status
from spartacloud.spartacloud_api import Spartacloud
spartacloud_obj = Spartacloud(api_key)
data_store_cluster_obj = spartacloud_obj.get_jobs_status()
- Cancel a job
from spartacloud.spartacloud_api import Spartacloud
spartacloud_obj = Spartacloud(api_key)
data_store_cluster_obj = spartacloud_obj.cancel_job(uuid)
- Cancel all jobs
from spartacloud.spartacloud_api import Spartacloud
spartacloud_obj = Spartacloud(api_key)
data_store_cluster_obj = spartacloud_obj.cancel_all_jobs()
- Delete a job
from spartacloud.spartacloud_api import Spartacloud
spartacloud_obj = Spartacloud(api_key)
data_store_cluster_obj = spartacloud_obj.delete_job(uuid)
- Get list of remote jobs
from spartacloud.spartacloud_api import Spartacloud
spartacloud_obj = Spartacloud(api_key)
data_store_cluster_obj = spartacloud_obj.get_jobs()
- Get stdout/stderr
from spartacloud.spartacloud_api import Spartacloud
spartacloud_obj = Spartacloud(api_key)
data_store_cluster_obj = spartacloud_obj.get_job_std(uuid)
Shared Resources
Coming soon...
Data Store
To interact with the Data Store (In-memory cluster-based), you need to instantiate the data store object:
from spartacloud.spartacloud_api import Spartacloud
spartacloud_obj = Spartacloud(api_key)
data_store_cluster_obj = spartacloud_obj.get_data_store_cluster()
You have the option to target a specific node of your cluster like this:
from spartacloud.spartacloud_api import Spartacloud
spartacloud_obj = Spartacloud(api_key)
data_store_cluster_obj = spartacloud_obj.get_data_store_cluster(target_node:int=1)
- Cluster Status
value = data_store_cluster_obj.status()
- Keys (get the list of keys for all the instances of your Spartacloud cluster)
value = data_store_cluster_obj.keys()
- Get
value = data_store_cluster_obj.get('my_key')
- Set
data_store_cluster_obj.set('my_key', 'my_value')
- Delete
data_store_cluster_obj.delete('my_key')
- Rpush
data_store_cluster_obj.rpush('my_list', 'item1', 'item2')
- Lrange
elements = spartacloud_obj.lrange('my_list', 0, -1)
- Hset
spartacloud_obj.hset('my_hash', 'field1', 'value1')
- Hget
value = spartacloud_obj.hget('my_hash', 'field1')
- Sadd
data_store_cluster_obj.sadd('my_set', 'member1', 'member2')
- Smembers
members = data_store_cluster_obj.smembers('my_set')
- Zadd
data_store_cluster_obj.zadd('my_sorted_set', {'item1': 10, 'item2': 5})
- Zrangebyscore
data_store_cluster_obj.zrangebyscore('my_sorted_set', min=0, max=20)
- Expire
data_store_cluster_obj.expire('my_key', 60)
- TTL
ttl = data_store_cluster_obj.ttl('my_key')
Check out the documentation of the API at https://spartaquant.pro/publicAPI for more information
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file spartacloud-0.3.tar.gz.
File metadata
- Download URL: spartacloud-0.3.tar.gz
- Upload date:
- Size: 2.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
97dfd461177d0f354da44904d296443d83c33ca8416d2991d3838d1e7fd27b3c
|
|
| MD5 |
bf03bb414cbce96dcc21eddd434d65e5
|
|
| BLAKE2b-256 |
470d75130a7b8b38c425eedc9f41cd669a35c1dbd29b7e230d870bb21b2e0c39
|
File details
Details for the file spartacloud-0.3-py3-none-any.whl.
File metadata
- Download URL: spartacloud-0.3-py3-none-any.whl
- Upload date:
- Size: 2.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
41fe81e8f2f402091b9ddce3ee01eae503edf5e5b2b5b96c92cb776b6b25e14a
|
|
| MD5 |
3c5eeb05e3fcbd631b42f65811170fb2
|
|
| BLAKE2b-256 |
77bf5d45037c69721e15940df0c926d136746fa2658c3c683ff134edf74a7cd5
|