class RelationshipClient: RELATIONSHIPS_URI = BASE_URI + "v2/relationship/" BULK_HEADERS = "bulk/headers" BULK_SET_CLASSIFICATIONS = "bulk/setClassifications" GET_RELATIONSHIP_BY_GUID = API(RELATIONSHIPS_URI + "guid", HTTPMethod.GET, HTTPStatus.OK) CREATE_RELATIONSHIP = API(RELATIONSHIPS_URI, HTTPMethod.POST, HTTPStatus.OK) UPDATE_RELATIONSHIP = API(RELATIONSHIPS_URI, HTTPMethod.PUT, HTTPStatus.OK) DELETE_RELATIONSHIP_BY_GUID = API(RELATIONSHIPS_URI + "guid", HTTPMethod.DELETE, HTTPStatus.NO_CONTENT) def __init__(self, client): self.client = client def get_relationship_by_guid(self, guid): return self.client.call_api(RelationshipClient.GET_RELATIONSHIP_BY_GUID.format_path_with_params(guid), AtlasRelationshipWithExtInfo) def get_relationship_by_guid_with_ext_info(self, guid, extended_info): query_params = {"extendedInfo": extended_info} return self.client.call_api(RelationshipClient.GET_RELATIONSHIP_BY_GUID.format_path_with_params(guid), AtlasRelationshipWithExtInfo, query_params) def create_relationship(self, relationship): return self.client.call_api(RelationshipClient.CREATE_RELATIONSHIP, AtlasRelationship, relationship) def update_relationship(self, relationship): return self.client.call_api(RelationshipClient.UPDATE_RELATIONSHIP, AtlasRelationship, relationship) def delete_relationship_by_guid(self, guid): return self.client.call_api(RelationshipClient.DELETE_RELATIONSHIP_BY_GUID.format_path_with_params(guid))
def __get_typedef_by_guid(self, guid, typedef_class): path_type = self.__get_path_for_type(typedef_class) api = API(TypeDefClient.GET_BY_GUID_TEMPLATE, HTTPMethod.GET, HTTPStatus.OK) return self.client.call_api( api.format_path({ 'path_type': path_type, 'guid': guid }), typedef_class)
def __get_typedef_by_name(self, name, typedef_class): path_type = self.__get_path_for_type(typedef_class) api = API(TypeDefClient.GET_BY_NAME_TEMPLATE, HTTPMethod.GET, HTTPStatus.OK) return self.client.call_api( api.format_path({ 'path_type': path_type, 'name': name }), typedef_class)
class LineageClient: LINEAGE_URI = BASE_URI + "v2/lineage" LINEAGE_INFO = API(LINEAGE_URI, HttpMethod.GET, HTTPStatus.OK) GET_LINEAGE_BY_ATTRIBUTES = API(LINEAGE_URI + "/uniqueAttribute/type/", HttpMethod.GET, HTTPStatus.OK) def __init__(self, client): self.client = client def get_lineage_info(self, guid, direction, depth): query_params = {"direction": direction, "depth": depth} return self.client.call_api(LineageClient.LINEAGE_INFO.format_path_with_params(guid), AtlasLineageInfo, query_params) def get_lineage_info_attr(self, type_name, attributes, direction, depth): query_params = attributes_to_params(attributes, {"direction": direction, "depth": depth}) return self.client.call_api(LineageClient.GET_LINEAGE_BY_ATTRIBUTES.format_path_with_params(type_name), AtlasLineageInfo, query_params)
class AdminClient: BASE_ADMIN_URL = BASE_URI + "admin/" GET_METRICS_API = API(BASE_ADMIN_URL + "metrics", HTTPMethod.GET, HTTPStatus.OK) def __init__(self, client): self.client = client def get_metrics(self): return self.client.call_api(AdminClient.GET_METRICS_API, AtlasAdminMetrics)
class TypeDefClient: TYPES_API = BASE_URI + "v2/types/" TYPEDEFS_API = TYPES_API + "typedefs/" TYPEDEF_BY_NAME = TYPES_API + "typedef/name" TYPEDEF_BY_GUID = TYPES_API + "typedef/guid" GET_BY_NAME_TEMPLATE = TYPES_API + "{path_type}/name/{name}" GET_BY_GUID_TEMPLATE = TYPES_API + "{path_type}/guid/{guid}" GET_TYPEDEF_BY_NAME = API(TYPEDEF_BY_NAME, HTTPMethod.GET, HTTPStatus.OK) GET_TYPEDEF_BY_GUID = API(TYPEDEF_BY_GUID, HTTPMethod.GET, HTTPStatus.OK) GET_ALL_TYPE_DEFS = API(TYPEDEFS_API, HTTPMethod.GET, HTTPStatus.OK) GET_ALL_TYPE_DEF_HEADERS = API(TYPEDEFS_API + "headers", HTTPMethod.GET, HTTPStatus.OK) CREATE_TYPE_DEFS = API(TYPEDEFS_API, HTTPMethod.POST, HTTPStatus.OK) DELETE_TYPE_DEFS = API(TYPEDEFS_API, HTTPMethod.DELETE, HTTPStatus.NO_CONTENT) DELETE_TYPE_DEF_BY_NAME = API(TYPEDEF_BY_NAME, HTTPMethod.DELETE, HTTPStatus.NO_CONTENT) def __init__(self, client): self.client = client def get_all_typedefs(self, search_filter): return self.client.call_api(TypeDefClient.GET_ALL_TYPE_DEFS, AtlasTypesDef, search_filter.params) def get_all_typedef_headers(self, search_filter): return self.client.call_api(TypeDefClient.GET_ALL_TYPE_DEF_HEADERS, list, search_filter.params) def type_with_guid_exists(self, guid): try: obj = self.client.call_api( TypeDefClient.GET_TYPEDEF_BY_GUID.format_path_with_params( guid), str) if obj is None: return False except Exception: return False return True def type_with_name_exists(self, name): try: obj = self.client.call_api( TypeDefClient.GET_TYPEDEF_BY_NAME.format_path_with_params( name), str) if obj is None: return False except Exception: return False return True def get_enumdef_by_name(self, name): return self.__get_typedef_by_name(name, AtlasEnumDef) def get_enumdef_by_guid(self, guid): return self.__get_typedef_by_guid(guid, AtlasEntityDef) def get_structdef_by_name(self, name): return self.__get_typedef_by_name(name, AtlasStructDef) def get_structdef_by_guid(self, guid): return self.__get_typedef_by_guid(guid, AtlasStructDef) def get_classificationdef_by_name(self, name): return self.__get_typedef_by_name(name, AtlasClassificationDef) def get_Classificationdef_by_guid(self, guid): return self.__get_typedef_by_guid(guid, AtlasClassificationDef) def get_entitydef_by_name(self, name): return self.__get_typedef_by_name(name, AtlasEntityDef) def get_entitydef_by_guid(self, guid): return self.__get_typedef_by_guid(guid, AtlasEntityDef) def get_relationshipdef_by_name(self, name): return self.__get_typedef_by_name(name, AtlasRelationshipDef) def get_relationshipdef_by_guid(self, guid): return self.__get_typedef_by_guid(guid, AtlasRelationshipDef) def get_businessmetadatadef_by_name(self, name): return self.__get_typedef_by_name(name, AtlasBusinessMetadataDef) def get_businessmetadatadef_by_guid(self, guid): return self.__get_typedef_by_guid(guid, AtlasBusinessMetadataDef) def create_atlas_typedefs(self, types_def): return self.client.call_api(TypeDefClient.CREATE_TYPE_DEFS, AtlasTypesDef, None, types_def) def update_atlas_typedefs(self, types_def): return self.client.call_api(TypeDefClient.UPDATE_TYPE_DEFS, AtlasTypesDef, None, types_def) def delete_atlas_typedefs(self, types_def): return self.client.call_api(TypeDefClient.DELETE_TYPE_DEFS, None, types_def) def delete_type_by_name(self, type_name): return self.client.call_api( TypeDefClient.DELETE_TYPE_DEF_BY_NAME.format_path_with_params( type_name)) def __get_typedef_by_name(self, name, typedef_class): path_type = self.__get_path_for_type(typedef_class) api = API(TypeDefClient.GET_BY_NAME_TEMPLATE, HTTPMethod.GET, HTTPStatus.OK) return self.client.call_api( api.format_path({ 'path_type': path_type, 'name': name }), typedef_class) def __get_typedef_by_guid(self, guid, typedef_class): path_type = self.__get_path_for_type(typedef_class) api = API(TypeDefClient.GET_BY_GUID_TEMPLATE, HTTPMethod.GET, HTTPStatus.OK) return self.client.call_api( api.format_path({ 'path_type': path_type, 'guid': guid }), typedef_class) def __get_path_for_type(self, typedef_class): if issubclass(AtlasEnumDef, typedef_class): return "enumdef" if issubclass(AtlasEntityDef, typedef_class): return "entitydef" if issubclass(AtlasClassificationDef, typedef_class): return "classificationdef" if issubclass(AtlasStructDef, typedef_class): return "structdef" if issubclass(AtlasRelationshipDef, typedef_class): return "relationshipdef" if issubclass(AtlasBusinessMetadataDef, typedef_class): return "businessmetadatadef" return ""
class DiscoveryClient: DISCOVERY_URI = BASE_URI + "v2/search" DSL_SEARCH_URI = DISCOVERY_URI + "/dsl" FULL_TEXT_SEARCH_URI = DISCOVERY_URI + "/fulltext" BASIC_SEARCH_URI = DISCOVERY_URI + "/basic" FACETED_SEARCH_URI = BASIC_SEARCH_URI SAVED_SEARCH_URI = DISCOVERY_URI + "/saved" QUICK_SEARCH_URI = DISCOVERY_URI + "/quick" DSL_SEARCH = API(DSL_SEARCH_URI, HttpMethod.GET, HTTPStatus.OK) FULL_TEXT_SEARCH = API(FULL_TEXT_SEARCH_URI, HttpMethod.GET, HTTPStatus.OK) BASIC_SEARCH = API(BASIC_SEARCH_URI, HttpMethod.GET, HTTPStatus.OK) FACETED_SEARCH = API(FACETED_SEARCH_URI, HttpMethod.POST, HTTPStatus.OK) ATTRIBUTE_SEARCH = API(DISCOVERY_URI + "/attribute", HttpMethod.GET, HTTPStatus.OK) RELATIONSHIP_SEARCH = API(DISCOVERY_URI + "/relationship", HttpMethod.GET, HTTPStatus.OK) QUICK_SEARCH_WITH_GET = API(QUICK_SEARCH_URI, HttpMethod.GET, HTTPStatus.OK) QUICK_SEARCH_WITH_POST = API(QUICK_SEARCH_URI, HttpMethod.POST, HTTPStatus.OK) GET_SUGGESTIONS = API(DISCOVERY_URI + "/suggestions", HttpMethod.GET, HTTPStatus.OK) # Saved Search GET_SAVED_SEARCHES = API(SAVED_SEARCH_URI, HttpMethod.GET, HTTPStatus.OK) GET_SAVED_SEARCH = API(SAVED_SEARCH_URI + "/{search_name}", HttpMethod.GET, HTTPStatus.OK) ADD_SAVED_SEARCH = API(SAVED_SEARCH_URI, HttpMethod.POST, HTTPStatus.OK) UPDATE_SAVED_SEARCH = API(SAVED_SEARCH_URI, HttpMethod.PUT, HTTPStatus.OK) DELETE_SAVED_SEARCH = API(SAVED_SEARCH_URI + "/{guid}", HttpMethod.DELETE, HTTPStatus.NO_CONTENT) EXECUTE_SAVED_SEARCH_BY_NAME = API( SAVED_SEARCH_URI + "/execute/{search_name}", HttpMethod.GET, HTTPStatus.OK) EXECUTE_SAVED_SEARCH_BY_GUID = API( SAVED_SEARCH_URI + "/execute/guid/{search_guid}", HttpMethod.GET, HTTPStatus.OK) QUERY = "query" LIMIT = "limit" OFFSET = "offset" STATUS = "Status" def __init__(self, client): self.client = client def dsl_search(self, query): query_params = {DiscoveryClient.QUERY, query} return self.client.call_api(DiscoveryClient.DSL_SEARCH, AtlasSearchResult, query_params) def dsl_search_with_params(self, query, limit, offset): query_params = { DiscoveryClient.QUERY: query, DiscoveryClient.LIMIT: limit, DiscoveryClient.OFFSET: offset } return self.client.call_api(DiscoveryClient.DSL_SEARCH, AtlasSearchResult, query_params) def full_text_search(self, query): query_params = {DiscoveryClient.QUERY, query} return self.client.call_api(DiscoveryClient.FULL_TEXT_SEARCH, AtlasSearchResult, query_params) def full_text_search_with_params(self, query, limit, offset): query_params = { DiscoveryClient.QUERY: query, DiscoveryClient.LIMIT: limit, DiscoveryClient.OFFSET: offset } return self.client.call_api(DiscoveryClient.FULL_TEXT_SEARCH, AtlasSearchResult, query_params) def basic_search(self, type_name, classification, query, exclude_deleted_entities, limit, offset): query_params = { "typeName": type_name, "classification": classification, DiscoveryClient.QUERY: query, "excludeDeletedEntities": exclude_deleted_entities, DiscoveryClient.LIMIT: limit, DiscoveryClient.OFFSET: offset } return self.client.call_api(DiscoveryClient.BASIC_SEARCH, AtlasSearchResult, query_params) def faceted_search(self, search_parameters): return self.client.call_api(DiscoveryClient.FACETED_SEARCH, AtlasSearchResult, search_parameters) def attribute_search(self, type_name, attr_name, attr_value_prefix, limit, offset): query_params = { "attrName": attr_name, "attrValuePrefix": attr_value_prefix, "typeName": type_name, DiscoveryClient.LIMIT: limit, DiscoveryClient.OFFSET: offset } return self.client.call_api(DiscoveryClient.ATTRIBUTE_SEARCH, AtlasSearchResult, query_params) def relationship_search(self, guid, relation, sort_by_attribute, sort_order, exclude_deleted_entities, limit, offset): query_params = { "guid": guid, "relation": relation, "sortBy": sort_by_attribute, "excludeDeletedEntities": exclude_deleted_entities, DiscoveryClient.LIMIT: limit, DiscoveryClient.OFFSET: offset } if sort_order: query_params["sortOrder"] = str(sort_order) return self.client.call_api(DiscoveryClient.RELATIONSHIP_SEARCH, AtlasSearchResult, query_params) def quick_search(self, query, type_name, exclude_deleted_entities, limit, offset): query_params = { "query": query, "typeName": type_name, "excludeDeletedEntities": exclude_deleted_entities, DiscoveryClient.LIMIT: limit, DiscoveryClient.OFFSET: offset } return self.client.call_api(DiscoveryClient.QUICK_SEARCH_WITH_GET, AtlasQuickSearchResult, query_params) def quick_search_with_param(self, quick_search_parameters): return self.client.call_api(DiscoveryClient.QUICK_SEARCH_WITH_POST, AtlasQuickSearchResult, None, quick_search_parameters) # fieldName should be the parameter on which indexing is enabled such as "qualifiedName" def get_suggestions(self, prefix_string, field_name): query_params = {} if not prefix_string: query_params["prefixString"] = prefix_string if not field_name: query_params["fieldName"] = field_name return self.client.call_api(DiscoveryClient.GET_SUGGESTIONS, AtlasSuggestionsResult, query_params) def get_saved_searches(self, user_name): query_params = {"user", user_name} return self.client.call_api(DiscoveryClient.GET_SAVED_SEARCHES, list, query_params) def get_saved_search(self, user_name, search_name): query_params = {"user", user_name} return self.client.call_api( DiscoveryClient.GET_SAVED_SEARCH.format_path( {'search_name': search_name}), AtlasUserSavedSearch, query_params) def add_saved_search(self, saved_search): return self.client.call_api(DiscoveryClient.ADD_SAVED_SEARCH, AtlasUserSavedSearch, None, saved_search) def update_saved_search(self, saved_search): return self.client.call_api(DiscoveryClient.UPDATE_SAVED_SEARCH, AtlasUserSavedSearch, None, saved_search) def delete_saved_search(self, guid): return self.client.call_api( DiscoveryClient.DELETE_SAVED_SEARCH.format_path({'guid': guid})) def execute_saved_search(self, user_name, search_name): query_params = {"user", user_name} return self.client.call_api( DiscoveryClient.EXECUTE_SAVED_SEARCH_BY_NAME.format_path( {'search_name': search_name}), AtlasSearchResult, query_params) def execute_saved_search(self, search_guid): return self.client.call_api( DiscoveryClient.EXECUTE_SAVED_SEARCH_BY_GUID.format_path( {'search_guid': search_guid}), AtlasSearchResult)
class EntityClient: ENTITY_API = BASE_URI + "v2/entity/" PREFIX_ATTR = "attr:" PREFIX_ATTR_ = "attr_" ADMIN_API = BASE_URI + "admin/" ENTITY_PURGE_API = ADMIN_API + "purge/" ENTITY_BULK_API = ENTITY_API + "bulk/" BULK_SET_CLASSIFICATIONS = "bulk/setClassifications" BULK_HEADERS = "bulk/headers" # Entity APIs GET_ENTITY_BY_GUID = API(ENTITY_API + "guid", HTTPMethod.GET, HTTPStatus.OK) GET_ENTITY_BY_UNIQUE_ATTRIBUTE = API(ENTITY_API + "uniqueAttribute/type", HTTPMethod.GET, HTTPStatus.OK) GET_ENTITIES_BY_GUIDS = API(ENTITY_BULK_API, HTTPMethod.GET, HTTPStatus.OK) GET_ENTITIES_BY_UNIQUE_ATTRIBUTE = API( ENTITY_BULK_API + "uniqueAttribute/type", HTTPMethod.GET, HTTPStatus.OK) GET_ENTITY_HEADER_BY_GUID = API(ENTITY_API + "guid/{entity_guid}/header", HTTPMethod.GET, HTTPStatus.OK) GET_ENTITY_HEADER_BY_UNIQUE_ATTRIBUTE = API( ENTITY_API + "uniqueAttribute/type/{type_name}/header", HTTPMethod.GET, HTTPStatus.OK) GET_AUDIT_EVENTS = API(ENTITY_API + "{guid}/audit", HTTPMethod.GET, HTTPStatus.OK) CREATE_ENTITY = API(ENTITY_API, HTTPMethod.POST, HTTPStatus.OK) CREATE_ENTITIES = API(ENTITY_BULK_API, HTTPMethod.POST, HTTPStatus.OK) UPDATE_ENTITY = API(ENTITY_API, HTTPMethod.POST, HTTPStatus.OK) UPDATE_ENTITY_BY_ATTRIBUTE = API(ENTITY_API + "uniqueAttribute/type/", HTTPMethod.PUT, HTTPStatus.OK) UPDATE_ENTITIES = API(ENTITY_BULK_API, HTTPMethod.POST, HTTPStatus.OK) PARTIAL_UPDATE_ENTITY_BY_GUID = API(ENTITY_API + "guid/{entity_guid}", HTTPMethod.PUT, HTTPStatus.OK) DELETE_ENTITY_BY_GUID = API(ENTITY_API + "guid", HTTPMethod.DELETE, HTTPStatus.OK) DELETE_ENTITY_BY_ATTRIBUTE = API(ENTITY_API + "uniqueAttribute/type/", HTTPMethod.DELETE, HTTPStatus.OK) DELETE_ENTITIES_BY_GUIDS = API(ENTITY_BULK_API, HTTPMethod.DELETE, HTTPStatus.OK) PURGE_ENTITIES_BY_GUIDS = API(ENTITY_PURGE_API, HTTPMethod.PUT, HTTPStatus.OK) # Classification APIs GET_CLASSIFICATIONS = API(ENTITY_API + "guid/{guid}/classifications", HTTPMethod.GET, HTTPStatus.OK) GET_FROM_CLASSIFICATION = API( ENTITY_API + "guid/{entity_guid}/classification/{classification}", HTTPMethod.GET, HTTPStatus.OK) ADD_CLASSIFICATIONS = API(ENTITY_API + "guid/{guid}/classifications", HTTPMethod.POST, HTTPStatus.NO_CONTENT) ADD_CLASSIFICATION = API(ENTITY_BULK_API + "/classification", HTTPMethod.POST, HTTPStatus.NO_CONTENT) ADD_CLASSIFICATION_BY_TYPE_AND_ATTRIBUTE = API( ENTITY_API + "uniqueAttribute/type/{type_name}/classifications", HTTPMethod.POST, HTTPStatus.NO_CONTENT) UPDATE_CLASSIFICATIONS = API(ENTITY_API + "guid/{guid}/classifications", HTTPMethod.PUT, HTTPStatus.NO_CONTENT) UPDATE_CLASSIFICATION_BY_TYPE_AND_ATTRIBUTE = API( ENTITY_API + "uniqueAttribute/type/{type_name}/classifications", HTTPMethod.PUT, HTTPStatus.NO_CONTENT) UPDATE_BULK_SET_CLASSIFICATIONS = API( ENTITY_API + BULK_SET_CLASSIFICATIONS, HTTPMethod.POST, HTTPStatus.OK) DELETE_CLASSIFICATION = API( ENTITY_API + "guid/{guid}/classification/{classification_name}", HTTPMethod.DELETE, HTTPStatus.NO_CONTENT) DELETE_CLASSIFICATION_BY_TYPE_AND_ATTRIBUTE = API( ENTITY_API + "uniqueAttribute/type/{type_name}/classification/{" "classification_name}", HTTPMethod.DELETE, HTTPStatus.NO_CONTENT) GET_BULK_HEADERS = API(ENTITY_API + BULK_HEADERS, HTTPMethod.GET, HTTPStatus.OK) # Business Attributes APIs ADD_BUSINESS_ATTRIBUTE = API( ENTITY_API + "guid/{entity_guid}/businessmetadata", HTTPMethod.POST, HTTPStatus.NO_CONTENT) ADD_BUSINESS_ATTRIBUTE_BY_NAME = API( ENTITY_API + "guid/{entity_guid}/businessmetadata/{bm_name}", HTTPMethod.POST, HTTPStatus.NO_CONTENT) DELETE_BUSINESS_ATTRIBUTE = API( ENTITY_API + "guid/{entity_guid}/businessmetadata", HTTPMethod.DELETE, HTTPStatus.NO_CONTENT) DELETE_BUSINESS_ATTRIBUTE_BY_NAME = API( ENTITY_API + "guid/{entity_guid}/businessmetadata/{bm_name}", HTTPMethod.DELETE, HTTPStatus.NO_CONTENT) GET_BUSINESS_METADATA_TEMPLATE = API( ENTITY_API + "businessmetadata/import/template", HTTPMethod.GET, HTTPStatus.OK, APPLICATION_JSON, APPLICATION_OCTET_STREAM) IMPORT_BUSINESS_METADATA = API(ENTITY_API + "businessmetadata/import", HTTPMethod.POST, HTTPStatus.OK, MULTIPART_FORM_DATA, APPLICATION_JSON) # Labels APIs ADD_LABELS = API(ENTITY_API + "guid/{entity_guid}/labels", HTTPMethod.PUT, HTTPStatus.NO_CONTENT) ADD_LABELS_BY_UNIQUE_ATTRIBUTE = API( ENTITY_API + "uniqueAttribute/type/{type_name}/labels", HTTPMethod.PUT, HTTPStatus.NO_CONTENT) SET_LABELS = API(ENTITY_API + "guid/%s/labels", HTTPMethod.POST, HTTPStatus.NO_CONTENT) SET_LABELS_BY_UNIQUE_ATTRIBUTE = API( ENTITY_API + "uniqueAttribute/type/{entity_guid}/labels", HTTPMethod.POST, HTTPStatus.NO_CONTENT) DELETE_LABELS = API(ENTITY_API + "guid/{entity_guid}/labels", HTTPMethod.DELETE, HTTPStatus.NO_CONTENT) DELETE_LABELS_BY_UNIQUE_ATTRIBUTE = API( ENTITY_API + "uniqueAttribute/type/{type_name}/labels", HTTPMethod.DELETE, HTTPStatus.NO_CONTENT) def __init__(self, client): self.client = client def get_entity_by_guid(self, guid, min_ext_info=False, ignore_relationships=False): query_params = { "minExtInfo": min_ext_info, "ignoreRelationships": ignore_relationships } return self.client.call_api( EntityClient.GET_ENTITY_BY_GUID.format_path_with_params(guid), AtlasEntityWithExtInfo, query_params) def get_entity_by_attribute(self, type_name, uniq_attributes, min_ext_info=False, ignore_relationships=False): query_params = attributes_to_params(uniq_attributes) query_params["minExtInfo"] = min_ext_info query_params["ignoreRelationships"] = ignore_relationships return self.client.call_api( EntityClient.GET_ENTITY_BY_UNIQUE_ATTRIBUTE. format_path_with_params(type_name), AtlasEntityWithExtInfo, query_params) def get_entities_by_guids(self, guids, min_ext_info=False, ignore_relationships=False): query_params = { "guid": guids, "minExtInfo": min_ext_info, "ignoreRelationships": ignore_relationships } return self.client.call_api(EntityClient.GET_ENTITIES_BY_GUIDS, AtlasEntitiesWithExtInfo, query_params) def get_entities_by_attribute(self, type_name, uniq_attributes_list, min_ext_info=False, ignore_relationships=False): query_params = list_attributes_to_params(uniq_attributes_list) query_params["minExtInfo"] = min_ext_info query_params["ignoreRelationships"] = ignore_relationships return self.client.call_api( EntityClient.GET_ENTITIES_BY_UNIQUE_ATTRIBUTE. format_path_with_params(type_name), AtlasEntitiesWithExtInfo, query_params) def get_entity_header_by_guid(self, entity_guid): return self.client.call_api( EntityClient.GET_ENTITY_HEADER_BY_GUID.format_path( {'entity_guid': entity_guid}), AtlasEntityHeader) def get_entity_header_by_attribute(self, type_name, uniq_attributes): query_params = attributes_to_params(uniq_attributes) return self.client.call_api( EntityClient.GET_ENTITY_HEADER_BY_UNIQUE_ATTRIBUTE.format_path( {'type_name': type_name}), AtlasEntityHeader, query_params) def get_audit_events(self, guid, start_key, audit_action, count): query_params = {"startKey": start_key, "count": count} if audit_action is not None: query_params["auditAction"] = audit_action return self.client.call_api( EntityClient.GET_AUDIT_EVENTS.format_path({'guid': guid}), list, query_params) def create_entity(self, entity): return self.client.call_api(EntityClient.CREATE_ENTITY, EntityMutationResponse, None, entity) def create_entities(self, atlas_entities): return self.client.call_api(EntityClient.CREATE_ENTITIES, EntityMutationResponse, None, atlas_entities) def update_entity(self, entity): return self.client.call_api(EntityClient.UPDATE_ENTITY, EntityMutationResponse, None, entity) def update_entities(self, atlas_entities): return self.client.call_api(EntityClient.UPDATE_ENTITY, EntityMutationResponse, None, atlas_entities) def partial_update_entity_by_guid(self, entity_guid, attr_value, attr_name): query_params = {"name": attr_name} return self.client.call_api( EntityClient.PARTIAL_UPDATE_ENTITY_BY_GUID.format_path( {'entity_guid': entity_guid}), EntityMutationResponse, query_params, attr_value) def delete_entity_by_guid(self, guid): return self.client.call_api( EntityClient.DELETE_ENTITY_BY_GUID.format_path_with_params(guid), EntityMutationResponse) def delete_entity_by_attribute(self, type_name, uniq_attributes): query_param = attributes_to_params(uniq_attributes) return self.client.call_api( EntityClient.DELETE_ENTITY_BY_ATTRIBUTE.format_path_with_params( type_name), EntityMutationResponse, query_param) def delete_entities_by_guids(self, guids): query_params = {"guid": guids} return self.client.call_api(EntityClient.DELETE_ENTITIES_BY_GUIDS, EntityMutationResponse, query_params) def purge_entities_by_guids(self, guids): return self.client.call_api(EntityClient.PURGE_ENTITIES_BY_GUIDS, EntityMutationResponse, None, guids) # Entity-classification APIs def get_classifications(self, guid): return self.client.call_api( EntityClient.GET_CLASSIFICATIONS.format_path({'guid': guid}), AtlasClassifications) def get_entity_classifications(self, entity_guid, classification_name): return self.client.call_api( EntityClient.GET_FROM_CLASSIFICATION.format_path({ 'entity_guid': entity_guid, 'classification': classification_name }), AtlasClassifications) def add_classification(self, request): self.client.call_api(EntityClient.ADD_CLASSIFICATION, None, None, request) def add_classifications_by_guid(self, guid, classifications): self.client.call_api( EntityClient.ADD_CLASSIFICATIONS.format_path({'guid': guid}), None, None, classifications) def add_classifications_by_type(self, type_name, uniq_attributes, classifications): query_param = attributes_to_params(uniq_attributes) self.client.call_api( EntityClient.ADD_CLASSIFICATION_BY_TYPE_AND_ATTRIBUTE.format_path( {'type_name': type_name}), None, query_param, classifications) def update_classifications(self, guid, classifications): self.client.call_api( EntityClient.UPDATE_CLASSIFICATIONS.format_path({'guid': guid}), None, None, classifications) def update_classifications_by_attr(self, type_name, uniq_attributes, classifications): query_param = attributes_to_params(uniq_attributes) self.client.call_api( EntityClient.UPDATE_CLASSIFICATION_BY_TYPE_AND_ATTRIBUTE. format_path({'type_name': type_name}), None, query_param, classifications) def set_classifications(self, entity_headers): return self.client.call_api( EntityClient.UPDATE_BULK_SET_CLASSIFICATIONS, str, None, entity_headers) def delete_classification(self, guid, classification_name): query = {'guid': guid, 'classification_name': classification_name} return self.client.call_api( EntityClient.DELETE_CLASSIFICATION.format_path(query)) def delete_classifications(self, guid, classifications): for atlas_classification in classifications: query = { 'guid': guid, 'classification_name': atlas_classification.typeName } self.client.call_api( EntityClient.DELETE_CLASSIFICATION.format_path(query)) def remove_classification(self, entity_guid, classification_name, associated_entity_guid): query = { 'guid': entity_guid, 'classification_name': classification_name } self.client.call_api( EntityClient.DELETE_CLASSIFICATION.formart_path(query), None, None, associated_entity_guid) def remove_classification_by_name(self, type_name, uniq_attributes, classification_name): query_params = attributes_to_params(uniq_attributes) query = { 'type_name': type_name, 'classification_name': classification_name } self.client.call_api( EntityClient.DELETE_CLASSIFICATION_BY_TYPE_AND_ATTRIBUTE. format_path({query}), None, query_params) def get_entity_headers(self, tag_update_start_time): query_params = {"tagUpdateStartTime", tag_update_start_time} return self.client.call_api(EntityClient.GET_BULK_HEADERS, AtlasEntityHeaders, query_params) # Business attributes APIs def add_or_update_business_attributes(self, entity_guid, is_overwrite, business_attributes): query_params = {"isOverwrite", is_overwrite} self.client.call_api( EntityClient.ADD_BUSINESS_ATTRIBUTE.format_path( {'entity_guid': entity_guid}), None, query_params, business_attributes) def add_or_update_business_attributes_bm_name(self, entity_guid, bm_name, business_attributes): query = {'entity_guid': entity_guid, 'bm_name': bm_name} self.client.call_api( EntityClient.ADD_BUSINESS_ATTRIBUTE_BY_NAME.format_path(query), None, None, business_attributes) def remove_business_attributes(self, entity_guid, business_attributes): self.client.call_api( EntityClient.DELETE_BUSINESS_ATTRIBUTE.format_path( {'entity_guid': entity_guid}), None, None, business_attributes) def remove_business_attributes_bm_name(self, entity_guid, bm_name, business_attributes): query = {'entity_guid': entity_guid, 'bm_name': bm_name} self.client.call_api( EntityClient.DELETE_BUSINESS_ATTRIBUTE_BY_NAME.format_path(query), None, None, business_attributes) # Labels APIs def add_labels_by_guid(self, entity_guid, labels): self.client.call_api( EntityClient.ADD_LABELS.format_path({'entity_guid': entity_guid}), None, None, labels) def add_labels_by_name(self, type_name, uniq_attributes, labels): query_param = attributes_to_params(uniq_attributes) self.client.call_api( EntityClient.SET_LABELS_BY_UNIQUE_ATTRIBUTE.format_path( {'type_name': type_name}), None, query_param, labels) def remove_labels_by_guid(self, entity_guid, labels): self.client.call_api( EntityClient.DELETE_LABELS.format_path( {'entity_guid': entity_guid}), None, None, labels) def remove_labels_by_name(self, type_name, uniq_attributes, labels): query_param = attributes_to_params(uniq_attributes) self.client.call_api( EntityClient.DELETE_LABELS_BY_UNIQUE_ATTRIBUTE.format( {'type_name': type_name}), None, query_param, labels) def set_labels_by_guid(self, entity_guid, labels): self.client.call_api( EntityClient.SET_LABELS.format({'entity_guid': entity_guid}), None, None, labels) def set_labels_by_name(self, type_name, uniq_attributes, labels): query_param = attributes_to_params(uniq_attributes) self.client.call_api( EntityClient.ADD_LABELS_BY_UNIQUE_ATTRIBUTE.format( {'type_name': type_name}), None, query_param, labels)
class GlossaryClient: GLOSSARY_URI = BASE_URI + "v2/glossary" GLOSSARY_TERM = GLOSSARY_URI + "/term" GLOSSARY_TERMS = GLOSSARY_URI + "/terms" GLOSSARY_CATEGORY = GLOSSARY_URI + "/category" GLOSSARY_CATEGORIES = GLOSSARY_URI + "/categories" GET_ALL_GLOSSARIES = API(GLOSSARY_URI, HTTPMethod.GET, HTTPStatus.OK) GET_GLOSSARY_BY_GUID = API(GLOSSARY_URI + "/{glossary_guid}", HTTPMethod.GET, HTTPStatus.OK) GET_DETAILED_GLOSSARY = API(GLOSSARY_URI + "/{glossary_guid}/detailed", HTTPMethod.GET, HTTPStatus.OK) GET_GLOSSARY_TERM = API(GLOSSARY_TERM, HTTPMethod.GET, HTTPStatus.OK) GET_GLOSSARY_TERMS = API(GLOSSARY_URI + "/{glossary_guid}/terms", HTTPMethod.GET, HTTPStatus.OK) GET_GLOSSARY_TERMS_HEADERS = API( GLOSSARY_URI + "/{glossary_guid}/terms/headers", HTTPMethod.GET, HTTPStatus.OK) GET_GLOSSARY_CATEGORY = API(GLOSSARY_CATEGORY, HTTPMethod.GET, HTTPStatus.OK) GET_GLOSSARY_CATEGORIES = API(GLOSSARY_URI + "/{glossary_guid}/categories", HTTPMethod.GET, HTTPStatus.OK) GET_GLOSSARY_CATEGORIES_HEADERS = API( GLOSSARY_URI + "/{glossary_guid}/categories/headers", HTTPMethod.GET, HTTPStatus.OK) GET_CATEGORY_TERMS = API(GLOSSARY_CATEGORY + "/{category_guid}/terms", HTTPMethod.GET, HTTPStatus.OK) GET_RELATED_TERMS = API(GLOSSARY_TERMS + "/{term_guid}/related", HTTPMethod.GET, HTTPStatus.OK) GET_RELATED_CATEGORIES = API( GLOSSARY_CATEGORY + "/{category_guid}/related", HTTPMethod.GET, HTTPStatus.OK) CREATE_GLOSSARY = API(GLOSSARY_URI, HTTPMethod.POST, HTTPStatus.OK) CREATE_GLOSSARY_TERM = API(GLOSSARY_TERM, HTTPMethod.POST, HTTPStatus.OK) CREATE_GLOSSARY_TERMS = API(GLOSSARY_TERMS, HTTPMethod.POST, HTTPStatus.OK) CREATE_GLOSSARY_CATEGORY = API(GLOSSARY_CATEGORY, HTTPMethod.POST, HTTPStatus.OK) CREATE_GLOSSARY_CATEGORIES = API(GLOSSARY_CATEGORIES, HTTPMethod.POST, HTTPStatus.OK) UPDATE_GLOSSARY_BY_GUID = API(GLOSSARY_URI + "/{glossary_guid}", HTTPMethod.PUT, HTTPStatus.OK) UPDATE_PARTIAL_GLOSSARY = API(GLOSSARY_URI + "/{glossary_guid}/partial", HTTPMethod.PUT, HTTPStatus.OK) UPDATE_GLOSSARY_TERM = API(GLOSSARY_TERM + "/{term_guid}", HTTPMethod.PUT, HTTPStatus.OK) UPDATE_PARTIAL_TERM = API(GLOSSARY_TERM + "/{term_guid}/partial", HTTPMethod.PUT, HTTPStatus.OK) UPDATE_CATEGORY_BY_GUID = API(GLOSSARY_CATEGORY + "/{category_guid}", HTTPMethod.PUT, HTTPStatus.OK) UPDATE_PARTIAL_CATEGORY = API( GLOSSARY_CATEGORY + "/{category_guid}/partial", HTTPMethod.PUT, HTTPStatus.OK) DELETE_GLOSSARY_BY_GUID = API(GLOSSARY_URI + "/{glossary_guid}", HTTPMethod.DELETE, HTTPStatus.NO_CONTENT) DELETE_TERM_BY_GUID = API(GLOSSARY_TERM + "/{term_guid}", HTTPMethod.DELETE, HTTPStatus.NO_CONTENT) DELETE_CATEGORY_BY_GUID = API(GLOSSARY_CATEGORY + "/{category_guid}", HTTPMethod.DELETE, HTTPStatus.NO_CONTENT) GET_ENTITIES_ASSIGNED_WITH_TERM = API( GLOSSARY_TERMS + "/{term_guid}/assignedEntities", HTTPMethod.GET, HTTPStatus.OK) ASSIGN_TERM_TO_ENTITIES = API( GLOSSARY_TERMS + "/{term_guid}/assignedEntities", HTTPMethod.POST, HTTPStatus.NO_CONTENT) DISASSOCIATE_TERM_FROM_ENTITIES = API( GLOSSARY_TERMS + "/{term_guid}/assignedEntities", HTTPMethod.PUT, HTTPStatus.NO_CONTENT) GET_IMPORT_GLOSSARY_TEMPLATE = API(GLOSSARY_URI + "/import/template", HTTPMethod.GET, HTTPStatus.OK, APPLICATION_JSON, APPLICATION_OCTET_STREAM) IMPORT_GLOSSARY = API(GLOSSARY_URI + "/import", HTTPMethod.POST, HTTPStatus.OK, MULTIPART_FORM_DATA, APPLICATION_JSON) QUERY = "query" LIMIT = "limit" OFFSET = "offset" STATUS = "Status" def __init__(self, client): self.client = client def get_all_glossaries(self, sort_by_attribute, limit, offset): query_params = { "sort": sort_by_attribute, GlossaryClient.LIMIT: limit, GlossaryClient.OFFSET: offset } return self.client.call_api(GlossaryClient.GET_ALL_GLOSSARIES, list, query_params) def get_glossary_by_guid(self, glossary_guid): return self.client.call_api( GlossaryClient.GET_GLOSSARY_BY_GUID.format_path( {'glossary_guid': glossary_guid}), AtlasGlossary) def get_glossary_ext_info(self, glossary_guid): return self.client.call_api( GlossaryClient.GET_DETAILED_GLOSSARY.format_path( {'glossary_guid': glossary_guid}), AtlasGlossaryExtInfo) def get_glossary_term(self, term_guid): return self.client.call_api( GlossaryClient.GET_GLOSSARY_TERM.format_path_with_params( term_guid), AtlasGlossaryTerm) def get_glossary_terms(self, glossary_guid, sort_by_attribute, limit, offset): query_params = { "glossaryGuid": glossary_guid, GlossaryClient.LIMIT: limit, GlossaryClient.OFFSET: offset, "sort": sort_by_attribute } return self.client.call_api( GlossaryClient.GET_GLOSSARY_TERMS.format_path( {'glossary_guid': glossary_guid}), list, query_params) def get_glossary_term_headers(self, glossary_guid, sort_by_attribute, limit, offset): query_params = { "glossaryGuid": glossary_guid, GlossaryClient.LIMIT: limit, GlossaryClient.OFFSET: offset, "sort": sort_by_attribute } return self.client.call_api( GlossaryClient.GET_GLOSSARY_TERMS_HEADERS.format_path( {'glossary_guid': glossary_guid}), list, query_params) def get_glossary_category(self, category_guid): return self.client.call_api( GlossaryClient.GET_GLOSSARY_CATEGORY.format_path_with_params( category_guid), AtlasGlossaryCategory) def get_glossary_categories(self, glossary_guid, sort_by_attribute, limit, offset): query_params = { "glossaryGuid": glossary_guid, GlossaryClient.LIMIT: limit, GlossaryClient.OFFSET: offset, "sort": sort_by_attribute } return self.client.call_api( GlossaryClient.GET_GLOSSARY_CATEGORIES.format_path( {'glossary_guid': glossary_guid}), list, query_params) def get_glossary_category_headers(self, glossary_guid, sort_by_attribute, limit, offset): query_params = { "glossaryGuid": glossary_guid, GlossaryClient.LIMIT: limit, GlossaryClient.OFFSET: offset, "sort": sort_by_attribute } return self.client.call_api( GlossaryClient.GET_GLOSSARY_CATEGORIES_HEADERS.format_path( {'glossary_guid': glossary_guid}), list, query_params) def get_category_terms(self, category_guid, sort_by_attribute, limit, offset): query_params = { "categoryGuid": category_guid, GlossaryClient.LIMIT: limit, GlossaryClient.OFFSET: offset, "sort": sort_by_attribute } return self.client.call_api( GlossaryClient.GET_CATEGORY_TERMS.format_path( {'category_guid': category_guid}), list, query_params) def get_related_terms(self, term_guid, sort_by_attribute, limit, offset): query_params = { "termGuid": term_guid, GlossaryClient.LIMIT: limit, GlossaryClient.OFFSET: offset, "sort": sort_by_attribute } return self.client.call_api( GlossaryClient.GET_RELATED_TERMS.format_path( {'term_guid': term_guid}), dict, query_params) def get_related_categories(self, category_guid, sort_by_attribute, limit, offset): query_params = { GlossaryClient.LIMIT: limit, GlossaryClient.OFFSET: offset, "sort": sort_by_attribute } return self.client.call_api( GlossaryClient.GET_RELATED_CATEGORIES.format_path( {'category_guid': category_guid}), dict, query_params) def create_glossary(self, glossary): return self.client.call_api(GlossaryClient.CREATE_GLOSSARY, AtlasGlossary, None, glossary) def create_glossary_term(self, glossary_term): return self.client.call_api(GlossaryClient.CREATE_GLOSSARY_TERM, AtlasGlossaryTerm, None, glossary_term) def create_glossary_terms(self, glossary_terms): return self.client.call_api(GlossaryClient.CREATE_GLOSSARY_TERMS, list, None, glossary_terms) def create_glossary_category(self, glossary_category): return self.client.call_api(GlossaryClient.CREATE_GLOSSARY_CATEGORY, AtlasGlossaryCategory, None, glossary_category) def create_glossary_categories(self, glossary_categories): return self.client.call_api(GlossaryClient.CREATE_GLOSSARY_CATEGORIES, list, glossary_categories) def update_glossary_by_guid(self, glossary_guid, updated_glossary): return self.client.call_api( GlossaryClient.UPDATE_GLOSSARY_BY_GUID.format_path( {'glossary_guid': glossary_guid}), AtlasGlossary, None, updated_glossary) def partial_update_glossary_by_guid(self, glossary_guid, attributes): return self.client.call_api( GlossaryClient.UPDATE_PARTIAL_GLOSSARY.format_path( {'glossary_guid': glossary_guid}), AtlasGlossary, attributes) def update_glossary_term_by_guid(self, term_guid, glossary_term): return self.client.call_api( GlossaryClient.UPDATE_GLOSSARY_TERM.format_path( {'term_guid': term_guid}), AtlasGlossaryTerm, None, glossary_term) def partial_update_term_by_guid(self, term_guid, attributes): return self.client.call_api( GlossaryClient.UPDATE_PARTIAL_TERM.format_path( {'term_guid': term_guid}), AtlasGlossaryTerm, attributes) def update_glossary_category_by_guid(self, category_guid, glossary_category): return self.client.call_api( GlossaryClient.UPDATE_CATEGORY_BY_GUID.format_path( {'category_guid': category_guid}), AtlasGlossaryCategory, glossary_category) def partial_update_category_by_guid(self, category_guid, attributes): return self.client.call_api( GlossaryClient.UPDATE_PARTIAL_CATEGORY.format_path( {'category_guid': category_guid}), AtlasGlossaryCategory, None, attributes) def delete_glossary_by_guid(self, glossary_guid): return self.client.call_api( GlossaryClient.DELETE_GLOSSARY_BY_GUID.format_path( {'glossary_guid': glossary_guid})) def delete_glossary_term_by_guid(self, term_guid): return self.client.call_api( GlossaryClient.DELETE_TERM_BY_GUID.format_path( {'term_guid': term_guid})) def delete_glossary_category_by_guid(self, category_guid): return self.client.call_api( GlossaryClient.DELETE_CATEGORY_BY_GUID.format_path( {'category_guid': category_guid})) def get_entities_assigned_with_term(self, term_guid, sort_by_attribute, limit, offset): query_params = { "termGuid": term_guid, GlossaryClient.LIMIT: limit, GlossaryClient.OFFSET: offset, "sort": sort_by_attribute } return self.client.call_api( GlossaryClient.GET_ENTITIES_ASSIGNED_WITH_TERM.format_path( {'term_guid': term_guid}), list, query_params) def assign_term_to_entities(self, term_guid, related_object_ids): return self.client.call_api( GlossaryClient.ASSIGN_TERM_TO_ENTITIES.format_path( {'term_guid': term_guid}), None, None, related_object_ids) def disassociate_term_from_entities(self, term_guid, related_object_ids): return self.client.call_api( GlossaryClient.DISASSOCIATE_TERM_FROM_ENTITIES.format_path( {'term_guid': term_guid}), None, None, related_object_ids)