
## Asset resources/links

URL: https://docs.atlan.com/product/capabilities/build-apps/sdks/python/how-tos/add-resources

> Add resources and external links to assets in Atlan using Link and the Python SDK (pyatlan). Create link assets and attach them programmatically.

# Link: add resources and external links to assets

Use `Link` in the Atlan Python SDK to programmatically add resources and external links to assets.

Resources (links) can only be added to [assets](https://docs.atlan.com/llms/platform/python/build-your-first-metadata-workflow/llms.txt) after an asset exists. (The asset itself must be created first.)

## Add to existing asset

Each resource can be assigned to only a single asset. To create a resource and assign it to an asset:

### dbt

Managing resources for assets is currently not possible via dbt.

### Java

```java showLineNumbers title="Add to an existing asset"
Table table = Table.refByQualifiedName("default/snowflake/1234567890/reln_db/reln_schema/customers"); // (1)
Link link = Link.creator( // (2)
 table, // (3)
 "Definition", // (4)
 "https://en.wikipedia.org/wiki/Customer") // (5)
 .build();
AssetMutationResponse response = link.save(client); // (6)
assert response.getCreatedAssets().size() == 1 // (7)
assert response.getUpdatedAssets().size() == 1 // (8)
```

1. Set up a reference to the asset you want to assign the resource to from somewhere. In this example, we just create a reference based on the qualifiedName of the asset we want, but this could also be from the result of a search, for example.
2. Use the `creator()` method to initialize the link with all [necessary attributes for creating it](https://docs.atlan.com/llms/platform/python/create-asset/llms.txt).
3. In the case of a link, you need to give a reference to an asset to which you want to attach the link.
4. And the title Atlan should display for the link.
5. And finally the URL for the link itself.
6. Call the `save()` method to actually create the link and attach it to the asset. Because this operation will persist the asset 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.
7. The response will include that single asset that was created (the link).
8. The response will also include a single asset that was updated (the asset to which you've attached the link).

### Python

```python showLineNumbers title="Add to an existing asset"
from pyatlan.client.atlan import AtlanClient
from pyatlan.model.assets import Link, Table

client = AtlanClient()
table = Table.ref_by_qualified_name("default/snowflake/1234567890/reln_db/reln_schema/customers") # (1)
link = Link.creator( # (2)
 asset=table, # (3)
 name="Definition", # (4)
 link="https://en.wikipedia.org/wiki/Customer") # (5)
response = client.asset.save(link) # (6)
assert (links := response.assets_created(asset_type=Link)) # (7)
assert (tables := response.assets_updated(asset_type=Table)) # (8)
```

1. Set up a reference to the asset you want to assign the resource to from somewhere. In this example, we just create a reference based on the qualified_name of the asset we want, but this could also be from the result of a search, for example.
2. Use the `create()` method to build a link with all [necessary attributes for creating it](https://docs.atlan.com/llms/platform/python/create-asset/llms.txt).
3. In the case of a link, you need to give a reference to an asset to which you want to attach the link.
4. And the title Atlan should display for the link.
5. And finally the URL for the link itself.
6. Call the `save()` method to actually create the link and attach it to the asset.
7. Assert that the link was created.
8. Assert a table was updated (the asset to which you've attached the link).

### Kotlin

```kotlin showLineNumbers title="Add to an existing asset"
val table = Table.refByQualifiedName("default/snowflake/1234567890/reln_db/reln_schema/customers") // (1)
val link = Link.creator( // (2)
 table, // (3)
 "Definition", // (4)
 "https://en.wikipedia.org/wiki/Customer") // (5)
 .build()
val response = link.save(client) // (6)
assert(response.createdAssets.size == 1) // (7)
assert(response.updatedAssets.size == 1) // (8)
```

1. Set up a reference to the asset you want to assign the resource to from somewhere. In this example, we just create a reference based on the qualifiedName of the asset we want, but this could also be from the result of a search, for example.
2. Use the `creator()` method to initialize the link with all [necessary attributes for creating it](https://docs.atlan.com/llms/platform/python/create-asset/llms.txt).
3. In the case of a link, you need to give a reference to an asset to which you want to attach the link.
4. And the title Atlan should display for the link.
5. And finally the URL for the link itself.
6. Call the `save()` method to actually create the link and attach it to the asset. Because this operation will persist the asset 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.
7. The response will include that single asset that was created (the link).
8. The response will also include a single asset that was updated (the asset to which you've attached the link).

### Raw REST API

:::warning[Note that you are actually creating a new link asset]
When adding a link through the API, you are really creating a new instance of a link asset. At the same time, you're attaching this new object to an existing asset.
:::
```json showLineNumbers title="POST /api/meta/entity/bulk"
{
 "entities": [ // (1)
 }
 ]
 }
 }
 ]
}
```

1. All assets must be wrapped in an `entities` array.
2. You must provide the exact type name for the link asset, which will always be `Link` (case-sensitive).
3. You must also provide a name for the link. This will show up on the UI as the title of the link.
4. You must also provide a unique `qualifiedName` for the link. This won't show up on the UI, and must be a unique UUID (generated yourself).
5. The URL for the link should be provided in the `link` field.
6. Finally, you need to include the reference information for the asset the link should be attached to.

## Remove from existing asset

To remove a link from an existing asset you only need to delete the link itself. (The link is itself an asset.)

See [Deleting an asset](https://docs.atlan.com/llms/platform/python/delete-asset/llms.txt).

:::warning[The link will have its own GUID, separate from the asset to which it's attached]
When deleting the link, you need to use the link's GUID, not the GUID of the asset to which it's attached.
:::

---
