Skip to main content

Spartacloud Python API

Project description

SpartaQuant icon 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
  1. First, you must pull the docker image on your server and create an account
  2. Go the cluster page, in the API section and generate an API key
  3. 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

  1. Get list of nodes
from spartacloud.spartacloud_api import Spartacloud
spartacloud_obj = Spartacloud(api_key)
spartacloud_obj.get_computer_nodes()
  1. Cluster metrics
from spartacloud.spartacloud_api import Spartacloud
spartacloud_obj = Spartacloud(api_key)
spartacloud_obj.get_metrics_cluster()
  1. Cluster status
from spartacloud.spartacloud_api import Spartacloud
spartacloud_obj = Spartacloud(api_key)
spartacloud_obj.get_status_cluster()
  1. Cluster CPU usage
from spartacloud.spartacloud_api import Spartacloud
spartacloud_obj = Spartacloud(api_key)
spartacloud_obj.get_cpu_cluster()
  1. Cluster MEM usage
from spartacloud.spartacloud_api import Spartacloud
spartacloud_obj = Spartacloud(api_key)
spartacloud_obj.get_mem_cluster()
  1. Cluster disk usage
from spartacloud.spartacloud_api import Spartacloud
spartacloud_obj = Spartacloud(api_key)
spartacloud_obj.get_disk_cluster()

Distributed Jobs

  1. 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
)
  1. Get job status
from spartacloud.spartacloud_api import Spartacloud
spartacloud_obj = Spartacloud(api_key)
data_store_cluster_obj = spartacloud_obj.get_jobs_status()
  1. Cancel a job
from spartacloud.spartacloud_api import Spartacloud
spartacloud_obj = Spartacloud(api_key)
data_store_cluster_obj = spartacloud_obj.cancel_job(uuid)
  1. Cancel all jobs
from spartacloud.spartacloud_api import Spartacloud
spartacloud_obj = Spartacloud(api_key)
data_store_cluster_obj = spartacloud_obj.cancel_all_jobs()
  1. Delete a job
from spartacloud.spartacloud_api import Spartacloud
spartacloud_obj = Spartacloud(api_key)
data_store_cluster_obj = spartacloud_obj.delete_job(uuid)
  1. Get list of remote jobs
from spartacloud.spartacloud_api import Spartacloud
spartacloud_obj = Spartacloud(api_key)
data_store_cluster_obj = spartacloud_obj.get_jobs()
  1. 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)
  1. Cluster Status
value = data_store_cluster_obj.status()
  1. Keys (get the list of keys for all the instances of your Spartacloud cluster)
value = data_store_cluster_obj.keys()
  1. Get
value = data_store_cluster_obj.get('my_key')
  1. Set
data_store_cluster_obj.set('my_key', 'my_value')
  1. Delete
data_store_cluster_obj.delete('my_key')
  1. Rpush
data_store_cluster_obj.rpush('my_list', 'item1', 'item2')
  1. Lrange
elements = spartacloud_obj.lrange('my_list', 0, -1)
  1. Hset
spartacloud_obj.hset('my_hash', 'field1', 'value1')
  1. Hget
value = spartacloud_obj.hget('my_hash', 'field1')
  1. Sadd
data_store_cluster_obj.sadd('my_set', 'member1', 'member2')
  1. Smembers
members = data_store_cluster_obj.smembers('my_set')
  1. Zadd
data_store_cluster_obj.zadd('my_sorted_set', {'item1': 10, 'item2': 5})
  1. Zrangebyscore
data_store_cluster_obj.zrangebyscore('my_sorted_set', min=0, max=20)
  1. Expire
data_store_cluster_obj.expire('my_key', 60)
  1. 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

spartacloud-0.3.tar.gz (2.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spartacloud-0.3-py3-none-any.whl (2.7 kB view details)

Uploaded Python 3

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

Hashes for spartacloud-0.3.tar.gz
Algorithm Hash digest
SHA256 97dfd461177d0f354da44904d296443d83c33ca8416d2991d3838d1e7fd27b3c
MD5 bf03bb414cbce96dcc21eddd434d65e5
BLAKE2b-256 470d75130a7b8b38c425eedc9f41cd669a35c1dbd29b7e230d870bb21b2e0c39

See more details on using hashes here.

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

Hashes for spartacloud-0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 41fe81e8f2f402091b9ddce3ee01eae503edf5e5b2b5b96c92cb776b6b25e14a
MD5 3c5eeb05e3fcbd631b42f65811170fb2
BLAKE2b-256 77bf5d45037c69721e15940df0c926d136746fa2658c3c683ff134edf74a7cd5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page