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.6.tar.gz (7.5 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.6-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: spartacloud-0.6.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.0

File hashes

Hashes for spartacloud-0.6.tar.gz
Algorithm Hash digest
SHA256 4f664bcb729518c5717259c634f395e7879738f65d3f6a51c5055bbd64c7af22
MD5 2d72031a3ffe1c0164ac77ef8c0a4a09
BLAKE2b-256 4fc597d72e633321c81b52e2aaa37995dc88800762a1d07a644552ebe3f720ec

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spartacloud-0.6-py3-none-any.whl
  • Upload date:
  • Size: 7.0 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.6-py3-none-any.whl
Algorithm Hash digest
SHA256 78397616143e0a9af0b4dc1f46f39a838ac598944d5b29eeab54dd27cdf17322
MD5 39568c34fefc6cdbe6fd94f00895e9d8
BLAKE2b-256 ee589932ef3a780a9ffdbcf1ec56e1ad82488fa69c4e747daa547755fafe8976

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