Skip to content

Latest commit

 

History

History
149 lines (104 loc) · 4.09 KB

README.md

File metadata and controls

149 lines (104 loc) · 4.09 KB

PyPI version

Swan SDK Orchestrator Samples

This directory contains samples for Swan Orchestrator. Swan Orchestrator is the Web3 cloud computing solution for tasks creation, deployment and management. User can create and manage tasks through samples under this directory. For more information checkout Swan Developer Docs.

Setup

Authentication (API Key)

Samples (and Swan SDK) requires you to have API Key from Swan Orchestrator.

Steps to get an API Key:

  • Go to Orchestrator Dashboard. Make sure you're under the Mainnet environment.
  • Login through MetaMask.
  • Click the user icon on the top right.
  • Click 'Show API-Key' -> 'New API Key'
  • Store your API Key safely, do not share with others.

Install Dependencies

  1. Clone the python-sdk-docs-samples and change directory to the directory you want to use.
$ git clone https://github.com/swanchain/python-sdk-docs-samples.git
  1. Install and updgrade pip and virtualenv if you do not already have them.
  2. Create virtualenv compatible with Python 3.7+
$ python3 -m venv venv
$ source venv/bin/activate
  1. Install the dependencies from the requirements file
$ pip install -r requirements.txt

Store Your Environment Variables Securely

  • public address will be required for authorization on Swan Orchestrator.
  • private address will be required for signing onchain transactions.
  • API key will be required for using Swan Orchestrator APIs.
WALLET_ADDRESS=<your_wallet_address>
PRIVATE_KEY=<your_private_key>
SWAN_API_KEY=<your_swan_api_key>

Run Samples

Get Instance Resources

This example shows how to retrieve all currently available CP resources online.

$ python compute/get_instance_resources.py

Instance Configuration Example

This example shows detailed breakdown of instance configuration structure and usage.

$ python compute/instance_configuration_example.py

Connect to Orchestrator (with Swan API Key)

This example shows how to connect to Orchestrator.

$ python compute/connect_orchestrator.py

Create Task

This example shows how to create task with Swan SDK.

$ python compute/create_task.py

Renew Task / Extend Task Duration

This example shows how to extend a task's duration.

$ python compute/renew_task.py '<task_uuid>'

Terminate Task

This example shows how to early terminate a task.

$ python compute/terminate_task.py '<task_uuid>'

Get Task List

This example shows how to get a list of tasks under the user of API Key and wallet address.

$ python compute/get_task_list.py

Get Task Deployment Info

This example shows how to get the task deployment info.

$ python compute/get_task_deployment_info.py '<task_uuid>'

Pre-approve Payment

This example shows how to approve an amount for payment in advance.

$ python compute/payment_approve.py

Other Examples

These examples shows how to deploy specific applications.

$ python compute/hello-world.py         # hello world app
$ python compute/deploy-chainnode.py    # chainnode app
$ python compute/deploy-llama3-model.py # llama3 model app