Deploying with Swan SDK
The Swan SDK is a toolkit designed to simplify interactions with the Swan Chain Network Resource. It provides a streamlined interface for creating and managing computational tasks, retrieving hardware information, processing payments, and monitoring task statuses.
Get Swan API Key
To use swan-sdk
, a Swan API key is required. Steps to get an API Key:
Go to Swan Console, switch network to Swan Chain Mainnet.
Login with your wallet.
Click
API Keys
->Generate API Key
Quick Start
Installation
To use Python Swan SDK, you first need to install it and its dependencies. Before installing Swan SDK, install Python 3.8 or later and web3.py(==6.20.3).
Install the latest Swan SDK release via pip:
pip install swan-sdk
Or install via GitHub:
git clone https://github.com/swanchain/python-swan-sdk.git
cd python-swan-sdk
pip install .
Using Python Swan SDK
To use Python Swan SDK, you must first import it and indicate which service you're going to use:
import swan
swan_orchestrator = swan.resource(api_key='<SWAN_API_KEY>', service_name='Orchestrator')
Now that you have an Orchestrator
service, you can create and deploy instance applications as an Orchestrator task with the service.
result = swan_orchestrator.create_task(
repo_uri='https://github.com/swanchain/awesome-swanchain/tree/main/hello_world', # Or your own repo URI
wallet_address='<WALLET_ADDRESS>',
private_key='<PRIVATE_KEY>',
instance_type='C1ae.medium'
)
task_uuid = result['task_uuid']
Then you can follow up task deployment information and the URL for running applications.
# Get task deployment info
task_deployment_info = swan_orchestrator.get_deployment_info(task_uuid=task_uuid)
print(task_deployment_info)
# Get application instances URL
app_urls = swan_orchestrator.get_real_url(task_uuid)
print(app_urls)
Documentation and Support
More resources about swan SDK can be found here:
Last updated