Retrieving assets
I need to do this before I can update an asset, right?
Strictly speaking, no, you don't. And in fact if you ultimately intend to update an asset you should trim it down to only what you intend to change and not send a complete asset. See Updating an asset for more details.
Retrieving an asset uses a slightly different pattern from the other operations. For this you can use static methods provided by the Asset class:
By GUID
To retrieve an asset by its GUID:
- Java
- Python
- Kotlin
- Raw REST API
Glossary glossary = Glossary
.get(client, "b4113341-251b-4adc-81fb-2420501c30e6"); // (1)
- If no exception is thrown, the returned object will be non-null and of the type requested. Because this operation will read the asset from Atlan, you must provide it an
AtlanClientthrough which to connect to the tenant.
This operation will type-check the asset you are retrieving is of the type requested. If it'sn't, you will receive a NotFoundException, even if the GUID represents some other asset.
from pyatlan.client.atlan import AtlanClient
from pyatlan.model.assets import AtlasGlossary, AtlasGlossaryTerm
client = AtlanClient()
glossary = client.asset.get_by_guid( # (1)
guid="b4113341-251b-4adc-81fb-2420501c30e6",
asset_type=AtlasGlossary,
min_ext_info=False,
ignore_relationships=True,
attributes=[AtlasGlossary.USER_DESCRIPTION, AtlasGlossary.TERMS],
related_attributes=[AtlasGlossaryTerm.USER_DESCRIPTION]
)
assert glossary and glossary.user_description
assert glossary.terms and len(glossary.terms) > 0
assert glossary.terms[0].user_description
-
client.asset.get_by_guid()method takes following parameters:guid: specify the (GUID) of the asset to retrieve.asset_type(optional): specify the type of asset to retrieve. Defaults toAsset. If no exception is thrown, the returned object will be non-null and of the type requested.min_ext_info(optional): minimizes additional information when set toTrue. Defaults toFalseignore_relationships(optional): specify whether to include relationships (False) or exclude them (True). Defaults toTrueattributes(optional): defines the list of attributes to retrieve for the asset. Accepts either a list of strings or a list ofAtlanField.related_attributes(optional): defines the list of relationship attributes to retrieve for the asset. Accepts either a list of strings or a list ofAtlanField.
Attributes and Related attributes
In this example, we're retrieving the userDescription attribute for
both the glossary and its terms. You can also retrieve other attributes as illustrated above.
:::
This operation will type-check the asset you are retrieving is of the type requested. If it'sn't, you will receive a NotFoundException, even if the GUID represents some other asset.
val glossary = Glossary
.get(client, "b4113341-251b-4adc-81fb-2420501c30e6") // (1)
- If no exception is thrown, the returned object will be non-null and of the type requested. Because this operation will read the asset from Atlan, you must provide it an
AtlanClientthrough which to connect to the tenant.
This operation will type-check the asset you are retrieving is of the type requested. If it'sn't, you will receive a NotFoundException, even if the GUID represents some other asset.
// (1)
- In the case of retrieving an asset, all necessary information is included in the URL of the request. There is no payload for the body of the request.
By GUID (runtime typing)
To retrieve an asset by GUID, but only resolve the type at runtime:
- Java
- Python
- Kotlin
- Raw REST API
Asset read = Asset
.get(client,
"b4113341-251b-4adc-81fb-2420501c30e6", // (1)
false);
Glossary glossary;
if (read instanceof Glossary)
- Retrieve the asset by its GUID. Since GUIDs are globally unique, you don't need to specify a type. (And this is why the operation returns a generic
Asset, since the SDK can only determine the type at runtime, once it has a response back from Atlan.) - Since the operation returns a generic
Asset, you need to check and cast it to a more specific type if you want to access the more specific attributes of that type.
from pyatlan.client.atlan import AtlanClient
from pyatlan.model.assets import AtlasGlossary, AtlasGlossaryTerm
client = AtlanClient()
glossary = client.asset.get_by_guid( # (1)
guid="b4113341-251b-4adc-81fb-2420501c30e6",
asset_type=AtlasGlossary,
min_ext_info=False,
ignore_relationships=True,
attributes=[AtlasGlossary.USER_DESCRIPTION, AtlasGlossary.TERMS],
related_attributes=[AtlasGlossaryTerm.USER_DESCRIPTION]
)
if isinstance(asset, AtlasGlossary): # (2)
glossary = asset
assert glossary and glossary.user_description
assert glossary.terms and len(glossary.terms) > 0
assert glossary.terms[0].user_description
-
client.asset.get_by_guid()method takes following parameters:guid: specify the (GUID) of the asset to retrieve.asset_type(optional): specify the type of asset to retrieve. Defaults toAsset. If no exception is thrown, the returned object will be non-null and of the type requested.min_ext_info(optional): minimizes additional information when set toTrue. Defaults toFalseignore_relationships(optional): specify whether to include relationships (False) or exclude them (True). Defaults toTrueattributes(optional): defines the list of attributes to retrieve for the asset. Accepts either a list of strings or a list ofAtlanField.related_attributes(optional): defines the list of relationship attributes to retrieve for the asset. Accepts either a list of strings or a list ofAtlanField.
Attributes and Related attributes
In this example, we're retrieving the userDescription attribute for
both the glossary and its terms. You can also retrieve other attributes as illustrated above.
:::
2. Since the operation returns a generic Asset, you need to use isinstance() to cast it to a more specific type in the block if you want an IDE to provide more specific type hints.
val read: Asset = Asset
.get(client,
"b4113341-251b-4adc-81fb-2420501c30e6", // (1)
false)
val glossary = if (read is Glossary) read else null // (2)
- Retrieve the asset by its GUID. Since GUIDs are globally unique, you don't need to specify a type. (And this is why the operation returns a generic
Asset, since the SDK can only determine the type at runtime, once it has a response back from Atlan.) - Since the operation returns a generic
Asset, you need to check and cast it to a more specific type if you want to access the more specific attributes of that type.
There is no concept of typing in a raw API request—all responses to the raw API will simply be JSON objects.
By qualifiedName
To retrieve an asset by its qualifiedName:
- Java
- Python
- Kotlin
- Raw REST API
Glossary glossary = Glossary
.get(client, "FzCMyPR2LxkPFgr8eNGrq"); // (1)
Table table = Table
.get(client, "default/snowflake/1657037873/SAMPLE_DB/FOOD_BEV/TOP_BEVERAGE_USERS"); // (2)
-
If no exception is thrown, the returned object will be non-null and of the type requested. Because this operation will read the asset from Atlan, you must provide it an
AtlanClientthrough which to connect to the tenant.Qualified name, not name
You must provide the qualifiedName for glossary objects (glossaries, categories, terms) to use this method. If you only know the name, you should instead use the findByName() operations.
:::
2. For most objects, you can probably build-up the qualifiedName in your code directly. Because this operation will read the asset from Atlan, you must provide it an AtlanClient through which to connect to the tenant.
The one exception is likely to be the connection portion of the name (default/snowflake/1657037873 in this example). To find this portion, see Find connections.
from pyatlan.client.atlan import AtlanClient
from pyatlan.model.assets import AtlasGlossary, AtlasGlossaryTerm, Table
client = AtlanClient()
glossary = client.asset.get_by_qualified_name( # (1)
asset_type=AtlasGlossary,
qualified_name="pXkf3RUvsIOIG8xnn0W3O",
min_ext_info=False,
ignore_relationships=True,
attributes=[AtlasGlossary.USER_DESCRIPTION, AtlasGlossary.TERMS],
related_attributes=[AtlasGlossaryTerm.USER_DESCRIPTION]
)
assert glossary and glossary.user_description
assert glossary.terms and len(glossary.terms) > 0
assert glossary.terms[0].user_description
table = client.asset.get_by_qualified_name(
asset_type=Table,
qualified_name="default/snowflake/1657037873/SAMPLE_DB/FOOD_BEV/TOP_BEVERAGE_USERS", # (2)
min_ext_info=False,
ignore_relationships=True,
attributes=[Table.USER_DESCRIPTION, Table.COLUMNS],
related_attributes=[COLUMN.USER_DESCRIPTION]
)
assert table and table.user_description
assert table.columns and len(table.columns) > 0
assert table.columns[0].user_description
-
client.asset.get_by_qualified_name()method takes following parameters:qualified_name: specify the qualified name of the asset to retrieve.asset_type: specify the type of asset to retrieve. If no exception is thrown, the returned object will be non-null and of the type requested.min_ext_info(optional): minimizes additional information when set toTrue. Defaults toFalseignore_relationships(optional): specify whether to include relationships (False) or exclude them (True). Defaults toTrueattributes(optional): defines the list of attributes to retrieve for the asset. Accepts either a list of strings or a list ofAtlanField.related_attributes(optional): defines the list of relationship attributes to retrieve for the asset. Accepts either a list of strings or a list ofAtlanField.
Attributes and Related attributes
In this example, we're retrieving the userDescription attribute for
both the glossary and its terms. You can also retrieve other attributes as illustrated above.
:::
2. For most objects, you can probably build-up the qualified_name in your code directly.
The one exception is likely to be the connection portion of the name (default/snowflake/1657037873 in this example). To find this portion, see Find connections.
val glossary = Glossary
.get(client, "FzCMyPR2LxkPFgr8eNGrq") // (1)
val table = Table
.get(client, "default/snowflake/1657037873/SAMPLE_DB/FOOD_BEV/TOP_BEVERAGE_USERS") // (2)
-
If no exception is thrown, the returned object will be non-null and of the type requested. Because this operation will read the asset from Atlan, you must provide it an
AtlanClientthrough which to connect to the tenant.Qualified name, not name
You must provide the qualifiedName for glossary objects (glossaries, categories, terms) to use this method. If you only know the name, you should instead use the findByName() operations.
:::
2. For most objects, you can probably build-up the qualifiedName in your code directly. Because this operation will read the asset from Atlan, you must provide it an AtlanClient through which to connect to the tenant.
The one exception is likely to be the connection portion of the name (default/snowflake/1657037873 in this example). To find this portion, see Find connections.
// (1)
-
In the case of retrieving an asset, all necessary information is included in the URL of the request. There is no payload for the body of the request.
URL encoding may be needed
Note that depending on the qualifiedName, you may need to URL-encode its value before sending. This is to replace any parts of the name that could be misinterpreted as actual URL components (like / or spaces).
:::
Full vs minimal assets
The examples above illustrate how to retrieve:
- an asset with all of its relationships (a complete asset).
- an asset without any of its relationships (a minimal asset).
You can also retrieve the opposite by explicitly requesting it:
- Java
- Python
- Kotlin
- Raw REST API
Glossary glossary = Glossary
.get(client,
"b4113341-251b-4adc-81fb-2420501c30e6",
true); // (1)
- Retrieve the full asset, with all of its relationships, by its GUID. The last (optional) parameter being
trueindicates you want to retrieve the asset with all its relationships (a "full" asset). Similar variations exist on every asset as well as on the dynamically-typedAssetstatic methods.
from pyatlan.client.atlan import AtlanClient
from pyatlan.model.assets import AtlasGlossary
client = AtlanClient()
glossary = client.asset.retrieve_minimal(
asset_type=AtlasGlossary, # (1)
guid="b4113341-251b-4adc-81fb-2420501c30e6"
)
- Optionally, you can provide the asset type:
- If no exception is thrown, the returned object will be non-null and of the type requested.
val glossary = Glossary
.get(client,
"b4113341-251b-4adc-81fb-2420501c30e6",
true) // (1)
- Retrieve the full asset, with all of its relationships, by its GUID. The last (optional) parameter being
trueindicates you want to retrieve the asset with all its relationships (a "full" asset). Similar variations exist on every asset as well as on the dynamically-typedAssetstatic methods.
// (1)
- In the case of retrieving an asset, all necessary information is included in the URL of the request. Retrieving a minimal asset is a matter of setting the query parameters
ignoreRelationshipsandminExtInfototrue.
You should retrieve minimal assets for better performance in cases where you don't need all of the relationships of the asset.
Keep in mind that although the relationships won't be visible in the object after retrieving a minimal asset, this does not mean that there are no relationships on that asset (in Atlan).