# 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.

{% hint style="info" %}
***For more sample tutorial, please refer to*** [***Python Swan SDK Samples***](https://github.com/swanchain/python-sdk-docs-samples) ***or*** [***Go Swan SDK Samples***](https://github.com/swanchain/go-swan-sdk-samples)***.***
{% endhint %}

### Get Swan API Key <a href="#get-orchestrator-api-key" id="get-orchestrator-api-key"></a>

To use `swan-sdk`, a Swan API key is required. Steps to get an API Key:

* Go to [Swan Console](https://console.swanchain.io/), switch network to [Swan Chain Mainnet](https://docs.swanchain.io/network-reference/readme).
* Login with your wallet.
* Click `API Keys` -> `Generate API Key`

## Quick Start <a href="#installation" id="installation"></a>

{% tabs %}
{% tab title="Python" %}
**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**:

```sh
pip install swan-sdk
```

Or install via GitHub:

```sh
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:

```python
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.

```python
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.

```python
# 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)
```

{% endtab %}

{% tab title="Go" %}
**Installation**

**Go Version**

`go-swan-sdk` requires [Go](https://go.dev/) version [1.21](https://go.dev/doc/devel/release#go1.21.0) or above.

**Using go-swan-sdk**

With [Go's module support](https://go.dev/wiki/Modules#how-to-use-modules), `go [build|run|test]` automatically fetches the necessary dependencies when you add `import`in your project:

```go
import "github.com/swanchain/go-swan-sdk"
```

To update the SDK use `go get -u` to retrieve the latest version of the SDK:

```go
go get -u github.com/swanchain/go-swan-sdk
```

**Quickstart**

To use `go-swan-sdk`, you must first import it, and you can create and deploy instance applications quickly.

```go
package main

import (
	"github.com/swanchain/go-swan-sdk"
	"log"
	"time"
)

func main() {
	client, err := swan.NewAPIClient("<YOUR_API_KEY>")
	if err != nil {
		log.Fatalf("failed to init swan client, error: %v \n", err)
	}
	task, err := client.CreateTask(&swan.CreateTaskReq{
		PrivateKey:   "<PRIVATE_KEY>",
		RepoUri:      "https://github.com/swanchain/awesome-swanchain/tree/main/hello_world",
		Duration:     2 * time.Hour,
		InstanceType: "C1ae.medium",
	})
	taskUUID := task.Task.UUID

	// Get task deployment info
	resp, err := client.TaskInfo(taskUUID)
	if err != nil {
		log.Fatalln(err)
	}
	log.Printf("task info: %+v \n", resp)

	//Get application instances URL
	appUrls, err := client.GetRealUrl(taskUUID)
	if err != nil {
		log.Fatalln(err)
	}
	log.Printf("app urls: %v \n", appUrls)
}

```

{% endtab %}
{% endtabs %}

### Documentation and Support <a href="#documentation-and-support" id="documentation-and-support"></a>

More resources about swan SDK can be found here:

* [Swan Console platform](https://console.swanchain.io/)
* [Python-swan-sdk](/bulders/tools/swan-sdk/python-swan-sdk.md)
* [Go-swan-sdk](/bulders/tools/swan-sdk/go-swan-sdk.md)
* [Python-swan-sdk-samples](https://github.com/swanchain/python-sdk-docs-samples)
* [Go-swan-sdk-samples](https://github.com/swanchain/go-swan-sdk-samples)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.swanchain.io/bulders/app-developer/deploying-with-swan-sdk.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
