/
read_entity_guid_or_name.py
46 lines (37 loc) · 1.6 KB
/
read_entity_guid_or_name.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import json
import os
# PyApacheAtlas packages
# Connect to Atlas via a Service Principal
from pyapacheatlas.auth import ServicePrincipalAuthentication
from pyapacheatlas.core import PurviewClient, AtlasEntity, AtlasProcess
if __name__ == "__main__":
"""
This sample provides an example of reading an existing entity
through the rest api / pyapacheatlas classes.
You need either the Guid of the entity or the qualified name and type name.
The schema of the response follows the /v2/entity/bulk GET operation
even if you are requesting only one entity by Guid.
https://atlas.apache.org/api/v2/json_AtlasEntitiesWithExtInfo.html
The response of get_entity will be a dict that has an "entities" key
that contains a list of the entities you requested.
"""
# Authenticate against your Atlas server
oauth = ServicePrincipalAuthentication(
tenant_id=os.environ.get("TENANT_ID", ""),
client_id=os.environ.get("CLIENT_ID", ""),
client_secret=os.environ.get("CLIENT_SECRET", "")
)
client = PurviewClient(
account_name = os.environ.get("PURVIEW_NAME", ""),
authentication=oauth
)
# When you know the GUID that you want to get
response = client.get_entity(guid="123-abc-456-def")
print(json.dumps(response, indent=2))
# When you need to find multiple Guids and they all are the same type
entities = client.get_entity(
qualifiedName=["qualifiedname1", "qualifiedname2", "qualifiedname3"],
typeName="my_type"
)
for entity in entities.get("entities"):
print(json.dumps(entity, indent=2))