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.2.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.2-py3-none-any.whl (2.7 kB view details)

Uploaded Python 3

File details

Details for the file spartacloud-0.2.tar.gz.

File metadata

  • Download URL: spartacloud-0.2.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.2.tar.gz
Algorithm Hash digest
SHA256 006906577ca1c82683d7c81740f0f547c94d1746823df52ec51c6bf99a93260e
MD5 ad60a986d3fcf4bb8bfcdd6b589684ea
BLAKE2b-256 f426069a7bb1e59477011410f3854e01a14c6dc321be9599905d4eb54c3f29b0

See more details on using hashes here.

File details

Details for the file spartacloud-0.2-py3-none-any.whl.

File metadata

  • Download URL: spartacloud-0.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 deceaddb0f2f135659b1179473483f5dcbc8339961b9d5767dfc62cb01c59e6f
MD5 24e98626a787dac1adb48d36afff28f7
BLAKE2b-256 0a7cdd5710113d37a0379a04eacb54a61077eaec37645ab28e8a4dd3b49b3999

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