Data Contextualization Clients for Python¶
Introduction¶
The Data Management related APIs handles the entire workflow of data registration and preparation. Data Contextualization provides a simple way to prepare data for establishing semantic correlations and data query processing.
Hint
Placeholders in the following samples are indicated by angular brackets < >
.
Data Lake Client¶
The data lake client manages, updates and retrieves the customer data lake information.
Client name: DataLakeClient
List all Data Lakes¶
# Import the RestClientConfig and UserToken from mindsphere_core module
from mindsphere_core import RestClientConfig
from mindsphere_core import UserToken
# Import the MindsphereError from mindsphere_core.exceptions module
from mindsphere_core.exceptions import MindsphereError
# Import the DataLakeClient from sdi module
from sdi import DataLakeClient
# Import all required models from sdi.models
from sdi import DataLakeList, CreateDataLakeRequest, UpdateDataLakeRequest
# Create the RestClientConfig and UserToken objects
config = RestClientConfig(
proxy_host = "<proxy_host>",
proxy_port = <proxy_port>
)
credentials = UserToken(
authorization = "<token>"
)
# Create the DataLakeClient object using the RestClientConfig and UserToken objects
dataLakeClient = DataLakeClient(
rest_client_config = config,
mindsphere_credentials = credentials
)
try:
# Initiate the API call to list data lakes
response = dataLakeClient.get_data_lakes()
except MindsphereError as err:
# Exception Handling
Create a Data Lake¶
# Create the DataLakeClient object as shown above
try:
# Create the CreateDataLakeRequest request object
createDataLakeRequest = CreateDataLakeRequest(
name = "<dataLake_name>",
type = "<dataLake_type>",
base_path = "<dataLake_basepath>"
)
# Initiate the API call to create the Data Lake
response = dataLakeClient.create_data_lakes(createDataLakeRequest)
except MindsphereError as err:
# Exception Handling
Update a Data Lake¶
# Create the DataLakeClient object as shown above
try:
# Create the UpdateDataLakeRequest request object
request_object = UpdateDataLakeRequest(
base_path = "<dataLake_basepath>"
)
# DataLake Id of the Data Lake to Update
id = "<datalake_id>"
# Initiate the API call to update a Data Lake
response = dataLakeClient.update_data_lakes_id(id, request_object)
except MindsphereError as err:
# Exception Handling
Retrieve a Data Lake by Id¶
# Create the DataLakeClient object as shown above
try:
# DataLake Id of the Data Lake to retrive
id = "<datalake_id>"
# Initiate the API call to get a Data Lake
response = dataLakeClient.get_data_lakes_id(id)
except MindsphereError as err:
# Exception Handling
Data Registry Client¶
The data registry client manages, updates, retrieves and deletes the created Data Registries.
Client name: DataRegistryClient
List all Data Registries¶
# Import the RestClientConfig and UserToken from mindsphere_core module
from mindsphere_core import RestClientConfig
from mindsphere_core import UserToken
# Import the MindsphereError from mindsphere_core.exceptions module
from mindsphere_core.exceptions import MindsphereError
# Import the DataRegistryClient from sdi module
from sdi.clients.data_registry_client import DataRegistryClient
# Import all required models from sdi.models
from sdi.models import QueryParaneters, CreateDataRegistryRequest, UpdateDataRegistryRequest
# Create the RestClientConfig and UserToken objects
config = RestClientConfig(
proxy_host = "<proxy_host>",
proxy_port = <proxy_port>
)
credentials = UserToken(
authorization = "<token>"
)
# Create the DataRegistryClient object using the RestClientConfig and UserToken objects
dataRegistryClient = DataRegistryClient(
rest_client_config = config,
mindsphere_credentials = credentials
)
try:
# Create the QueryParaneters request object
queryParaneters = QueryParaneters(
data_tag = "<data_tag>",
source_name = "<source_name>",
page_token = "<page_token>"
)
# Initiate the API call to list data registries
response = dataRegistryClient.get_data_registries(queryParameters)
except MindsphereError as err:
# Exception Handling
Create a Data Registry¶
# Create the DataRegistryClient object as shown above
try:
# Create the CreateDataRegistryRequest request object
createDataRegistryRequest = CreateDataRegistryRequest(
data_tag = "<data_tag>",
default_root_tag = "<default_root_tag>",
file_pattern = "<file_pattern>",
file_upload_strategy = "replace" | "append",
meta_data_tags = [
"string"
],
source_name = "string",
xml_process_rules = [
"string"
],
partition_keys = [
"string"
],
schema_frozen = False
)
# Initiate the API call to create the Data Registry
response = dataRegistryClient.create_data_registries(createDataRegistryRequest)
except MindsphereError as err:
# Exception Handling
Update a Data Registry¶
# Create the DataRegistryClient object as shown above
try:
# Create the UpdateDataRegistryRequest request object
request_object = UpdateDataRegistryRequest(
default_root_tag = "<default_root_tag>",
file_pattern = "<file_pattern>",
file_upload_strategy = "replace" | "append",
meta_data_tags = [
"string"
],
xml_process_rules = [
"string"
],
schema_frozen = False
)
# DataRegistry Id of the Data Registry to Update
id = "<data_registry_id>"
# Initiate the API call
response = dataRegistryClient.update_data_registries_id(id, request_object)
except MindsphereError as err:
# Exception Handling
Retrieve a Data Registry by Id¶
# Create the DataRegistryClient object as shown above
try:
# DataRegsitry Id of the Data Registry to retrive
id = "<data_registry_id>"
# Initiate the API call
response = dataRegistryClient.get_data_registries_id(id)
except MindsphereError as err:
# Exception Handling
Delete a Data Registry by Id¶
# Create the DataRegistryClient object as shown above
try:
# DataRegsitry Id of the Data Registry to delete
id = "<data_registry_id>"
# Initiate the API call
response = dataRegistryClient.delete_data_registries_id(id)
except MindsphereError as err:
# Exception Handling
Iot Data Registry Client¶
Operations to manage and keep track of DataRegistry dedicated for IoT Data.
Client name: IotDataRegistryClient
List all Iot Data Registries¶
# Import the RestClientConfig and UserToken from mindsphere_core module
from mindsphere_core import RestClientConfig
from mindsphere_core import UserToken
# Import the MindsphereError from mindsphere_core.exceptions module
from mindsphere_core.exceptions import MindsphereError
# Import the IotDataRegistryClient from sdi module
from sdi.clients.iot_dataregistry_client import IotDataRegistryClient
# Import all required models from sdi.models
from sdi.models import QueryParaneters, IotDataRegistry
# Create the RestClientConfig and UserToken objects
config = RestClientConfig(
proxy_host = "<proxy_host>",
proxy_port = <proxy_port>
)
credentials = UserToken(
authorization = "<token>"
)
# Create the IotDataRegistryClient object using the RestClientConfig and UserToken objects
iotDataRegistryClient = IotDataRegistryClient(
rest_client_config = config,
mindsphere_credentials = credentials
)
try:
# Create the QueryParaneters request object
queryParaneters = QueryParaneters(
filter = "<filter>",
page_token = "<page_token>"
)
# Initiate the API call
response = iotDataRegistryClient.get_iot_data_registries(queryParameters)
except MindsphereError as err:
# Exception Handling
Create a Iot Data Registry¶
# Create the IotDataRegistryClient object as shown above
try:
# Create the IotDataRegistry request object
request_object = IotDataRegistry(
asset_id = "<asset_id>",
aspect_name = "<aspect_name>"
)
# Initiate the API call
response = iotDataRegistryClient.create_iot_data_registries(request_object)
except MindsphereError as err:
# Exception Handling
Custom Data Types Client¶
Operations to manage and keep track of custom data types.
Client name: CustomDatatypesClient
List all Custom Datatypes¶
# Import the RestClientConfig and UserToken from mindsphere_core module
from mindsphere_core import RestClientConfig
from mindsphere_core import UserToken
# Import the MindsphereError from mindsphere_core.exceptions module
from mindsphere_core.exceptions import MindsphereError
# Import the CustomDatatypesClient from sdi module
from sdi.clients.custom_datatypes_client import CustomDatatypesClient
# Import all required models from sdi.models
from sdi.models import QueryParaneters, DataTypeDefinition, DataTypePattern, SuggestPatternsPostRequest
# Create the RestClientConfig and UserToken objects
config = RestClientConfig(
proxy_host = "<proxy_host>",
proxy_port = <proxy_port>
)
credentials = UserToken(
authorization = "<token>"
)
# Create the CustomDatatypesClient object using the RestClientConfig and UserToken objects
customDatatypesClient = CustomDatatypesClient(
rest_client_config = config,
mindsphere_credentials = credentials
)
try:
# Create the QueryParaneters request object
queryParaneters = QueryParaneters(
page_token = "<page_token>"
)
# Initiate the API call
response = customDatatypesClient.get_data_types(queryParameters)
except MindsphereError as err:
# Exception Handling
Create a Custom Datatype¶
# Create the CustomDatatypesClient object as shown above
try:
# Create the DataTypeDefinition request object
dataTypeDefinition = DataTypeDefinition(
name = "<name>",
patterns = [
"[A-HJ-NPR-Z0-9]{17}"
]
)
# Initiate the API call
response = customDatatypesClient.create_data_types(dataTypeDefinition)
except MindsphereError as err:
# Exception Handling
Update a Custom Datatype¶
# Create the CustomDatatypesClient object as shown above
try:
# Create the DataTypePattern request object
request_object = DataTypePattern(
patterns = [
"string"
]
)
# Name of the Custom Data Type to Update
name = "<custom_datatype_name>"
# Initiate the API call
response = customDatatypesClient.update_data_types_name_add_patterns(name, request_object)
except MindsphereError as err:
# Exception Handling
Retrieve a Custom Datatype by Name¶
# Create the CustomDatatypesClient object as shown above
try:
# Name of the Custom Data Type to Retrieve
name = "<custom_datatype_name>"
# Initiate the API call
response = customDatatypesClient.get_data_types_name(name)
except MindsphereError as err:
# Exception Handling
Delete a Custom Datatype by Name¶
# Create the CustomDatatypesClient object as shown above
try:
# Name of the Custom Data Type to Retrieve
name = "<custom_datatype_name>"
# Initiate the API call
response = customDatatypesClient.delete_data_types_name(name)
except MindsphereError as err:
# Exception Handling
Generate a Suggest Pattern¶
# Create the CustomDatatypesClient object as shown above
try:
# Create the Suggest Pattern request object
request_object = SuggestPatternsPostRequest(
sample_values = [
"<string>"
],
test_values = [
"<string>"
]
)
# Initiate the API call
response = customDatatypesClient.create_suggest_patterns(request_object)
except MindsphereError as err:
# Exception Handling
Data Ingest Client¶
Operations to upload the file and ingest the data into Data Contextualization system. This service is entry point for Data Contextualization's schema generation operations for the current tenant and file.
Client name: DataIngestClient
Data Upload by File¶
# Import the RestClientConfig and UserToken from mindsphere_core module
from mindsphere_core import RestClientConfig
from mindsphere_core import UserToken
# Import the MindsphereError from mindsphere_core.exceptions module
from mindsphere_core.exceptions import MindsphereError
# Import the DataIngestClient from sdi module
from sdi.clients.data_ingest_client import DataIngestClient
# Import all required models from sdi.models
from sdi.models import SDIIngestData, QueryParameters
# Create the RestClientConfig and UserToken objects
config = RestClientConfig(
proxy_host = "<proxy_host>",
proxy_port = <proxy_port>
)
credentials = UserToken(
authorization = "<token>"
)
# Create the DataIngestClient object using the RestClientConfig and UserToken objects
dataIngestClient = DataIngestClient(
rest_client_config = config,
mindsphere_credentials = credentials
)
try:
# Create the File request object
request_object = open("<path_to_file>","r")
# Initiate the API call
response = dataIngestClient.create_data_upload(request_object)
except MindsphereError as err:
# Exception Handling
Create an Ingest Job¶
# Create the DataIngestClient object as shown above
try:
# Create the SDIIngestData request object
request_object = SDIIngestData(
data_tag = "<data_tag>",
file_path = "<file_path>",
root_tag = "<root_tag>",
source_name = "<source_name>"
)
# Initiate the API call
response = dataIngestClient.create_ingest_jobs(request_object)
except MindsphereError as err:
# Exception Handling
Retrieve Ingest Job Statuses¶
# Create the DataIngestClient object as shown above
try:
# Create the QueryParameters request object
queryParameters = QueryParameters(
page_token = "<page_token>"
)
# Initiate the API call
response = dataIngestClient.get_ingest_job_status(queryParameters)
except MindsphereError as err:
# Exception Handling
Retrieve Ingest Job Status By Id¶
# Create the DataIngestClient object as shown above
try:
# Id of the Ingest Job to Retrieve
id = "<ingest_job_id>"
# Initiate the API call
response = dataIngestClient.get_ingest_job_status_id(id)
except MindsphereError as err:
# Exception Handling
Schema Registry Client¶
Search schema for ingested data.
Client name: SchemaRegistryClient
Search Schemas¶
# Import the RestClientConfig and UserToken from mindsphere_core module
from mindsphere_core import RestClientConfig
from mindsphere_core import UserToken
# Import the MindsphereError from mindsphere_core.exceptions module
from mindsphere_core.exceptions import MindsphereError
# Import the SchemaRegistryClient from sdi module
from sdi.clients.schema_registry_client import SchemaRegistryClient
# Import all required models from sdi.models
from sdi.models import SchemaSearchRequest, QueryParameters
# Create the RestClientConfig and UserToken objects
config = RestClientConfig(
proxy_host = "<proxy_host>",
proxy_port = <proxy_port>
)
credentials = UserToken(
authorization = "<token>"
)
# Create the SchemaRegistryClient object using the RestClientConfig and UserToken objects
schemaRegistryClient = SchemaRegistryClient(
rest_client_config = config,
mindsphere_credentials = credentials
)
try:
# Create the QueryParameters request object
queryParameters = QueryParameters(
page_token = "<page_token>"
)
# Create the SchemaSearchRequest request object
request_object = SchemaSearchRequest(
schemas = [
{
data_tag = "<data_tag>",
schema_name = "<schema_name>",
category = "<category>",
aspect_name = "<aspect_name>",
asset_id = "<asset_id>",
source_name = "<source_name>",
meta_data_tags = [
"<meta_data_tags>"
]
}
]
)
# Initiate the API call
response = schemaRegistryClient.create_search_schemas(queryParameters, request_object)
except MindsphereError as err:
# Exception Handling
Data Query Operations Client¶
Client to manage and execute data queries
Client name: DataQueryOperationsClient
Retrieve all Queries¶
# Import the RestClientConfig and UserToken from mindsphere_core module
from mindsphere_core import RestClientConfig
from mindsphere_core import UserToken
# Import the MindsphereError from mindsphere_core.exceptions module
from mindsphere_core.exceptions import MindsphereError
# Import the DataQueryOperationsClient from sdi module
from sdi.clients.data_ingest_client import DataQueryOperationsClient
# Import all required models from sdi.models
from sdi.models import QueryParameters, DataQuerySQLRequest, DataQuerySQLUpdateRequest, DataQueryExecuteQueryRequest, Parameters, Aliases
# Create the RestClientConfig and UserToken objects
config = RestClientConfig(
proxy_host = "<proxy_host>",
proxy_port = <proxy_port>
)
credentials = UserToken(
authorization = "<token>"
)
# Create the DataQueryOperationsClient object using the RestClientConfig and UserToken objects
dataQueryOperationsClient = DataQueryOperationsClient(
rest_client_config = config,
mindsphere_credentials = credentials
)
try:
# Create the QueryParameters request object
queryParameters = QueryParameters(
page_token = "<page_token>",
executable = "<executable>",
is_dynamic = "<is_dynamic>",
ontology_id = "<ontology_id>"
)
# Initiate the API call
response = dataQueryOperationsClient.get_queries(queryParameters)
except MindsphereError as err:
# Exception Handling
Create a Query¶
# Create the DataQueryOperationsClient object as shown above
try:
# Create the DataQuerySQLRequest request object
request_object = DataQuerySQLRequest(
is_business_query = "<is_business_query>",
ontology_id = "<ontology_id>",
is_dynamic = "<is_dynamic>",
name = "<name>",
sql_statement = "<sql_statement_base64_encoded>"
)
# Initiate the API call
response = dataQueryOperationsClient.create_queries(request_object)
except MindsphereError as err:
# Exception Handling
Retrieve a Query by Id¶
# Create the DataQueryOperationsClient object as shown above
try:
# Id of the Query to Retrieve
id = <query_id>
# Initiate the API call
response = dataQueryOperationsClient.get_queries_id(id)
except MindsphereError as err:
# Exception Handling
Update a Query by Id¶
# Create the DataQueryOperationsClient object as shown above
try:
# Id of the Query to Update
id = <query_id>
# Create the DataQuerySQLUpdateRequest request object
request_object = DataQuerySQLUpdateRequest(
description = "<description>",
is_business_query = "<is_business_query>",
ontology_id = "<ontology_id>",
is_dynamic = "<is_dynamic>",
name = "<name>",
sql_statement = "<sql_statement_base64_encoded>"
)
# Initiate the API call
response = dataQueryOperationsClient.update_queries_id(id, request_object)
except MindsphereError as err:
# Exception Handling
Delete a Query by Id¶
# Create the DataQueryOperationsClient object as shown above
try:
# Id of the Query to Delete
id = <query_id>
# Initiate the API call
response = dataQueryOperationsClient.delete_queries_id(id)
except MindsphereError as err:
# Exception Handling
Create a Query Execution Job for Dynamic Query¶
# Create the DataQueryOperationsClient object as shown above
try:
# Id of the Query to Delete
id = <query_id>
# Create a Parameter
paramter = Parameters(
param_name = "<param_name>",
param_value = "<param_value>"
)
# Create an Alias
alias = Aliases(
attribute_name = "<attribute_name>",
alias_value = "<alias_value>"
)
# Create a DataQueryExecuteQueryRequest rerquest object
request_object = DataQueryExecuteQueryRequest(
description = "<description>"
parameters = [
parameter
],
aliases = [
alias
]
)
# Initiate the API call
response = dataQueryOperationsClient.create_queries_id_execution_jobs(id, request_object)
except MindsphereError as err:
# Exception Handling
Retrieve the Latest Execution Job Results by Query Id¶
# Create the DataQueryOperationsClient object as shown above
try:
# Id of the Query executing the Job
id = "<query_id>"
# Range of the file to return in Bytes
range = "<range>"
# Initiate the API call
response = dataQueryOperationsClient.get_queries_id_execution_jobs_latest_results(id, range)
except MindsphereError as err:
# Exception Handling
Retrieve a Execution Job by Execution Job Id¶
# Create the DataQueryOperationsClient object as shown above
try:
# Id of the Execution Job to Retrieve
id = <execution_job_id>
# Initiate the API call
response = dataQueryOperationsClient.get_execution_jobs_id(id)
except MindsphereError as err:
# Exception Handling
Retrieve a Execution Job Result by Execution Job Id¶
# Create the DataQueryOperationsClient object as shown above
try:
# Id of the Execution Job Results to Retrieve
id = "<execution_job_id>"
# Range of the file to return in Bytes
range = "<range>"
# Initiate the API call
response = dataQueryOperationsClient.get_execution_jobs_id_results(id, range)
except MindsphereError as err:
# Exception Handling
Delete a Execution Job by Execution Job Id¶
# Create the DataQueryOperationsClient object as shown above
try:
# Id of the Execution Job to Delete
id = <execution_job_id>
# Initiate the API call
response = dataQueryOperationsClient.delete_execution_jobs_id(id)
except MindsphereError as err:
# Exception Handling
Retrieve all Execution Jobs¶
# Create the DataQueryOperationsClient object as shown above
try:
# Create the QueryParameters request object
queryParameters = QueryParameters(
page_token = "<page_token>",
query_id = "<query_id>",
status = "<status>"
)
# Initiate the API call
response = dataQueryOperationsClient.delete_execution_jobs_id(queryParameters)
except MindsphereError as err:
# Exception Handling
Ontologies Client¶
Client to manage ontologies
Client name: OntologiesClient
Retrieve all Ontologies¶
# Import the RestClientConfig and UserToken from mindsphere_core module
from mindsphere_core import RestClientConfig
from mindsphere_core import UserToken
# Import the MindsphereError from mindsphere_core.exceptions module
from mindsphere_core.exceptions import MindsphereError
# Import the OntologiesClient from sdi module
from sdi.clients.ontologies_client import OntologiesClient
# Import all required models from sdi.models
from sdi.models import QueryParameters, InferSearchObject, InferSchemaSearchRequest
# Create the RestClientConfig and UserToken objects
config = RestClientConfig(
proxy_host = "<proxy_host>",
proxy_port = <proxy_port>
)
credentials = UserToken(
authorization = "<token>"
)
# Create the OntologiesClient object using the RestClientConfig and UserToken objects
ontologiesClient = OntologiesClient(
rest_client_config = config,
mindsphere_credentials = credentials
)
try:
# Create the QueryParameters request object
queryParameters = QueryParameters(
page_token = "<page_token>"
)
# Initiate the API call
response = ontologiesClient.get_ontologies(queryParameters)
except MindsphereError as err:
# Exception Handling
Retrieve a Ontology by Id¶
# Create the OntologiesClient object as shown above
try:
# Id of the Query to Retrieve
id = <ontology_id>
# Range of the file to return in Bytes
range = "<range>"
# Initiate the API call
response = ontologiesClient.get_ontologies_id(id, range)
except MindsphereError as err:
# Exception Handling
Delete a Ontology by Id¶
# Create the OntologiesClient object as shown above
try:
# Id of the Query to Delete
id = <ontology_id>
# Initiate the API call
response = ontologiesClient.delete_ontologies_id(id)
except MindsphereError as err:
# Exception Handling
Infer an Ontology¶
# Create the OntologiesClient object as shown above
try:
# Create an InferSearchObject
inferSearchObject = InferSearchObject(
data_tag = "<data_tag>",
schema_name = "<schema_name>",
source_name = "<source_name>",
asset_id = "<asset_id>",
aspect_name = "<aspect_name>"
)
# Create the InferSchemaSearchRequest request object
request_object = InferSchemaSearchRequest(
schemas = [
inferSearchObject
],
exclude_properties = [
"<exclude_properties>"
]
)
# Initiate the API call
response = ontologiesClient.infer_ontology(request_object)
except MindsphereError as err:
# Exception Handling
Ontologies Operations Client¶
Client to manage ontology jobs to create and update ontologies
Client name: OntologiesClient
Create an Ontology Job¶
# Import the RestClientConfig and UserToken from mindsphere_core module
from mindsphere_core import RestClientConfig
from mindsphere_core import UserToken
# Import the MindsphereError from mindsphere_core.exceptions module
from mindsphere_core.exceptions import MindsphereError
# Import the OntologiesOperationsClient from sdi module
from sdi.clients.ontologies_operations_client import OntologiesOperationsClient
# Import all required models from sdi.models
from sdi.models import OntologyCreateRequest
# Create the RestClientConfig and UserToken objects
config = RestClientConfig(
proxy_host = "<proxy_host>",
proxy_port = <proxy_port>
)
credentials = UserToken(
authorization = "<token>"
)
# Create the OntologiesOperationsClient object using the RestClientConfig and UserToken objects
ontologiesOperationsClient = OntologiesOperationsClient(
rest_client_config = config,
mindsphere_credentials = credentials
)
try:
# Create the OntologyCreateRequest request object
request_object = OntologyCreateRequest(
ontology_description = "<ontology_description>",
ontology_id = "<ontology_id>",
ontology_name = "<ontology_name>",
key_mapping_type = "<key_mapping_type>",
file = "<file>"
)
# Initiate the API call
response = ontologiesOperationsClient.create_ontology_jobs(request_object)
except MindsphereError as err:
# Exception Handling
Retrieve a Ontology Job by Id¶
# Create the OntologiesOperationsClient object as shown above
try:
# Id of the Query to Retrieve
id = <ontology_job_id>
# Initiate the API call
response = ontologiesOperationsClient.get_ontology_jobs_id(id)
except MindsphereError as err:
# Exception Handling
Except where otherwise noted, content on this site is licensed under the Development License Agreement.