
## Delete connection

URL: https://docs.atlan.com/product/capabilities/build-apps/sdks/python/packages/how-tos/delete-connection

> Delete a connection and its related assets in Atlan using ConnectionDelete and the Python SDK (pyatlan). Supports soft-delete (archive) and hard-delete (purge).

# ConnectionDelete: delete a connection and its assets

Use `ConnectionDelete` in the Atlan Python SDK to programmatically delete a connection and all its related assets.

The [connection delete package](https://ask.atlan.com/hc/en-us/articles/6755306791697)
deletes a connection and all its related assets.

## Soft-delete (archive) assets

To soft-delete (archive) all assets in a connection:

### Java

```java showLineNumbers title="Archive assets"
Workflow workflow = ConnectionDelete.creator( // (1)
 "default/snowflake/1234567890", false // (2)
 ).build() // (3)
 .toWorkflow(); // (4)

WorkflowResponse response = workflow.run(client); // (5)
```

1. The `ConnectionDelete` package will create a workflow to delete a connection and its assets using the `creator()` method.
2. You need to provide the following:

 - qualified name of the connection whose assets should be deleted.
 - whether to permanently delete the connection and its assets (hard-delete) (`true`), or only archive (soft-delete) them (`false`).

3. Build the minimal package object.
4. Convert the package into a `Workflow` object.
5. Run the workflow using the `run()` method on the object you've created. Because this operation will execute work in Atlan, you must [provide it an `AtlanClient`](https://docs.atlan.com/llms/platform/python/set-up-sdk/llms.txt) through which to connect to the tenant.

 :::warning[Workflows run asynchronously]
Remember that workflows run asynchronously. See the [packages and workflows introduction](https://docs.atlan.com/llms/platform/python/packages/llms.txt) for details on how to check the status and wait until the workflow has been completed.
 :::

### Python

```python showLineNumbers title="Archive assets"
from pyatlan.client.atlan import AtlanClient
from pyatlan.model.packages import ConnectionDelete

client = AtlanClient()

workflow = ConnectionDelete( # (1)
 qualified_name="default/snowflake/1234567890", purge=False # (2)
).to_workflow() # (3)

response = client.workflow.run(workflow) # (4)
```

1. The `ConnectionDelete` package will create
a workflow to delete a connection and its assets.
2. You need to provide the following:

 - qualified name of the connection whose assets should be deleted.
 - whether to permanently delete the connection and its assets
 (hard-delete) (`True`), or only archive (soft-delete) them (`False`).

3. Convert the package into a `Workflow` object.
4. Run the workflow by invoking the `run()` method
on the workflow client, passing the created object.

 :::warning[Workflows run asynchronously]
Remember that workflows run asynchronously.
See the [packages and workflows introduction](https://docs.atlan.com/llms/platform/python/packages/llms.txt)
for details on how to check the status and wait
until the workflow has been completed.
 :::

### Kotlin

```kotlin showLineNumbers title="Archive assets"
val workflow = ConnectionDelete.creator( // (1)
 "default/snowflake/1234567890", false // (2)
 ).build() // (3)
 .toWorkflow() // (4)

val response = workflow.run(client) // (5)
```

1. The `ConnectionDelete` package will create a workflow to delete a connection and its assets using the `creator()` method.
2. You need to provide the following:

 - qualified name of the connection whose assets should be deleted.
 - whether to permanently delete the connection and its assets (hard-delete) (`true`), or only archive (soft-delete) them (`false`).

3. Build the minimal package object.
4. Convert the package into a `Workflow` object.
5. Run the workflow using the `run()` method on the object you've created. Because this operation will execute work in Atlan, you must [provide it an `AtlanClient`](https://docs.atlan.com/llms/platform/python/set-up-sdk/llms.txt) through which to connect to the tenant.

 :::warning[Workflows run asynchronously]
Remember that workflows run asynchronously. See the [packages and workflows introduction](https://docs.atlan.com/llms/platform/python/packages/llms.txt) for details on how to check the status and wait until the workflow has been completed.
 :::

### Raw REST API

:::tip[Create the workflow via UI only]
We recommend creating the workflow only via the UI.
To rerun an existing workflow, see the steps below.
:::

## Hard-delete (purge) assets

:::warning[Permanent and irreversible]
A hard-delete (purge) is permanent and irreversible.
Be certain that you want to entirely remove all of the
assets in a connection before running in this way!
:::
To hard-delete (purge) all assets in a connection:

### Java

```java showLineNumbers title="Purge assets"
Workflow workflow = ConnectionDelete.creator( // (1)
 "default/snowflake/1234567890", true // (2)
 ).build() // (3)
 .toWorkflow(); // (4)

WorkflowResponse response = workflow.run(client); // (5)
```

1. The `ConnectionDelete` package will create a workflow to delete a connection and its assets using the `creator()` method.
2. You need to provide the following:

 - qualified name of the connection whose assets should be deleted.
 - whether to permanently delete the connection and its assets (hard-delete) (`true`), or only archive (soft-delete) them (`false`).

3. Build the minimal package object.
4. Convert the package into a `Workflow` object.
5. Run the workflow using the `run()` method on the object you've created. Because this operation will execute work in Atlan, you must [provide it an `AtlanClient`](https://docs.atlan.com/llms/platform/python/set-up-sdk/llms.txt) through which to connect to the tenant.

 :::warning[Workflows run asynchronously]
Remember that workflows run asynchronously. See the [packages and workflows introduction](https://docs.atlan.com/llms/platform/python/packages/llms.txt) for details on how to check the status and wait until the workflow has been completed.
 :::

### Python

```python showLineNumbers title="Purge assets"
from pyatlan.client.atlan import AtlanClient
from pyatlan.model.packages import ConnectionDelete

client = AtlanClient()

workflow = ConnectionDelete( # (1)
 qualified_name="default/snowflake/1234567890", purge=True # (2)
).to_workflow() # (3)

response = client.workflow.run(workflow) # (4)
```

1. The `ConnectionDelete` package will create
a workflow to delete a connection and its assets.
2. You need to provide the following:

 - qualified name of the connection whose assets should be deleted.
 - whether to permanently delete the connection and its assets
 (hard-delete) (`True`), or only archive (soft-delete) them (`False`).

3. Convert the package into a `Workflow` object.
4. Run the workflow by invoking the `run()` method
on the workflow client, passing the created object.

 :::warning[Workflows run asynchronously]
Remember that workflows run asynchronously.
See the [packages and workflows introduction](https://docs.atlan.com/llms/platform/python/packages/llms.txt)
for details on how to check the status and wait
until the workflow has been completed.
 :::

### Kotlin

```kotlin showLineNumbers title="Purge assets"
val workflow = ConnectionDelete.creator( // (1)
 "default/snowflake/1234567890", true // (2)
 ).build() // (3)
 .toWorkflow() // (4)

val response = workflow.run(client) // (5)
```

1. The `ConnectionDelete` package will create a workflow to delete a connection and its assets using the `creator()` method.
2. You need to provide the following:

 - qualified name of the connection whose assets should be deleted.
 - whether to permanently delete the connection and its assets (hard-delete) (`true`), or only archive (soft-delete) them (`false`).

3. Build the minimal package object.
4. Convert the package into a `Workflow` object.
5. Run the workflow using the `run()` method on the object you've created. Because this operation will execute work in Atlan, you must [provide it an `AtlanClient`](https://docs.atlan.com/llms/platform/python/set-up-sdk/llms.txt) through which to connect to the tenant.

 :::warning[Workflows run asynchronously]
Remember that workflows run asynchronously. See the [packages and workflows introduction](https://docs.atlan.com/llms/platform/python/packages/llms.txt) for details on how to check the status and wait until the workflow has been completed.
 :::

### Raw REST API

:::tip[Create the workflow via UI only]
We recommend creating the workflow only via the UI.
To rerun an existing workflow, see the steps below.
:::

## Re-run existing workflow

To re-run an existing connection delete workflow:

### Java

```java showLineNumbers title="Re-run existing connection delete workflow"
List existing = WorkflowSearchRequest // (1)
 .findByType(client, ConnectionDelete.PREFIX, 5); // (2)
// Determine which of the results is the Connection delete workflow you want to re-run...
WorkflowRunResponse response = existing.get(n).rerun(client); // (3)
```

1. You can search for existing workflows through the `WorkflowSearchRequest` class.
2. You can find workflows by their type using the `findByType()` helper method and providing the prefix for one of the packages. In this example, we do so for the `ConnectionDelete`. (You can also specify the maximum number of resulting workflows you want to retrieve as results.)
3. Once you've found the workflow you want to re-run, you can simply call the `rerun()` helper method on the workflow search result. The `WorkflowRunResponse` is just a subtype of `WorkflowResponse` so has the same helper method to monitor progress of the workflow run. Because this operation will execute work in Atlan, you must [provide it an `AtlanClient`](https://docs.atlan.com/llms/platform/python/set-up-sdk/llms.txt) through which to connect to the tenant.

 - Optionally, you can use the `rerun(client, true)` method with idempotency to avoid re-running a workflow that's already in running or in a pending state. This will return details of the already running workflow if found, and by default, it's set to `false`

 :::warning[Workflows run asynchronously]
Remember that workflows run asynchronously. See the [packages and workflows introduction](https://docs.atlan.com/llms/platform/python/packages/llms.txt) for details on how you can check the status and wait until the workflow has been completed.
 :::

### Python

```python showLineNumbers title="Re-run existing connection delete workflow"
from pyatlan.client.atlan import AtlanClient
from pyatlan.model.enums import WorkflowPackage

client = AtlanClient()

existing = client.workflow.find_by_type( # (1)
 prefix=WorkflowPackage.CONNECTION_DELETE, max_results=5
)

# Determine which Connection delete workflow (n)

# from the list of results you want to re-run.

response = client.workflow.rerun(existing[n]) # (2)
```

1. You can find workflows by their type using the workflow client `find_by_type()`
method and providing the **prefix** for one of the packages.
In this example, we do so for the `ConnectionDelete`. (You can also specify
the **maximum number of resulting workflows** you want to retrieve as results.)
2. Once you've found the workflow you want to re-run,
you can simply call the workflow client `rerun()` method.

 - Optionally, you can use `rerun(idempotent=True)` to avoid re-running a workflow that's already in running or in a pending state.
 This will return details of the already running workflow if found, and by default, it's set to `False`.

 :::warning[Workflows run asynchronously]
Remember that workflows run asynchronously. See the [packages and workflows introduction](https://docs.atlan.com/llms/platform/python/packages/llms.txt)
for details on how you can check the status and wait until the workflow has been completed.
 :::

### Kotlin

```kotlin showLineNumbers title="Re-run existing connection delete workflow"
val existing = WorkflowSearchRequest // (1)
 .findByType(client, ConnectionDelete.PREFIX, 5) // (2)
// Determine which of the results is the
// connection delete workflow you want to re-run...
val response = existing.get(n).rerun(client) // (3)
```

1. You can search for existing workflows through the `WorkflowSearchRequest` class.
2. You can find workflows by their type using the `findByType()` helper method and providing the prefix for one of the packages. In this example, we do so for the `ConnectionDelete`. (You can also specify the maximum number of resulting workflows you want to retrieve as results.)
3. Once you've found the workflow you want to re-run, you can simply call the `rerun()` helper method on the workflow search result. The `WorkflowRunResponse` is just a subtype of `WorkflowResponse` so has the same helper method to monitor progress of the workflow run. Because this operation will execute work in Atlan, you must [provide it an `AtlanClient`](https://docs.atlan.com/llms/platform/python/set-up-sdk/llms.txt) through which to connect to the tenant.

 - Optionally, you can use the `rerun(client, true)` method with idempotency to avoid re-running a workflow that's already in running or in a pending state. This will return details of the already running workflow if found, and by default, it's set to `false`

 :::warning[Workflows run asynchronously]
Remember that workflows run asynchronously. See the [packages and workflows introduction](https://docs.atlan.com/llms/platform/python/packages/llms.txt) for details on how you can check the status and wait until the workflow has been completed.
 :::

### Raw REST API

:::warning[Requires multiple steps through the raw REST API]
1. Find the existing workflow.
2. Send through the resulting re-run request.
:::
```json showLineNumbers title="POST /api/service/workflows/indexsearch"
{
 "from": 0,
 "size": 5,
 "query": {
 "bool": {
 "filter": [
 {
 "nested": {
 "path": "metadata",
 "query": {
 "prefix": {
 "metadata.name.keyword": {
 "value": "atlan-connection-delete" // (1)
 }
 }
 }
 }
 }
 ]
 }
 },
 "sort": [
 {
 "metadata.creationTimestamp": {
 "nested": {
 "path": "metadata"
 },
 "order": "desc"
 }
 }
 ],
 "track_total_hits": true
}
```

1. Searching by the `atlan-connection-delete` prefix will make sure you only find existing connection delete workflows.

 :::tip[Name of the workflow]
The name of the workflow will be nested within the `_source.metadata.name` property of the response object.
(Remember since this is a search, there could be multiple results, so you may want to use the other details
in each result to determine which workflow you really want.)
 :::
```json title="POST /api/service/workflows/submit"
{
 "namespace": "default",
 "resourceKind": "WorkflowTemplate",
 "resourceName": "atlan-connection-delete-1684500411" // (1)
}
```

1. Send the name of the workflow as the `resourceName` to rerun it.

---
