Package: acceldata-sdk
Pipeline APIsAcceldata Torch is a complete solution to observe the quality of the data present in your data lake and warehouse. Using Torch, you can ensure that high-quality data backs your business decisions. Torch provides you with tools to measure the quality of data in a data catalog and to never miss significant data sources. All users including analysts, data scientists, and developers, can rely on Torch to observe the data flowing in the warehouse or data lake and can rest assured that there is no loss of data.Acceldata SDK is used to trigger torch catalog and pipeline APIs. By creating a Torch client, all the torch apis can be accessed.Installacceldata-sdkpypi package in a python environment.pipinstallacceldata-sdkCreate Torch ClientTorch client is used to send data to the torch servers. It consists of various methods to communicate with the torch server. Torch client have access to catalog and pipeline APIs. To create a torch client, torch url and API keys are required. To create torch API keys, go to torch ui’s settings and generate keys for the client.While creating a TorchClient connection to torch by default version compatibility checks between torch and sdk is enabled. If we want we can disable that check by passingdo_version_checkas `False.fromacceldata_sdk.torch_clientimportTorchClienttorch_client=TorchClient(url='https://acceldata.host.dev:9999',access_key='******',secret_key='*****************',do_version_check=True)Pipeline APIThere are various pipeline APIs are supported through Acceldata SDK. Pipeline APIs like create pipeline, add jobs and spans, initiate pipeline run et cetera. Acceldata sdk is able to send various event during span life cycle. Hence, Acceldata sdk has full control over the pipelines.Create Pipeline And Job and span to bound the jobPipelinerepresents the ETL pipeline in its entirety and will contain Asset nodes and Jobs associated. The complete pipeline definition forms the Lineage graph for all the data assets.Job NodeorProcess Noderepresents an entity that does some job in the ETL workflow. From this representation,Job’s inputis some assets or some other Jobs, and output is few other assets or few other Jobs.
Torch will use the set of Jobs definition in the workflow to create the Lineage, and also track version changes for the Pipeline.Acceldata sdk providesCreateJobclass which need to be passed tocreate_jobfunction as a parameter to create a job.Params forCreateJob:uid: uid of the job. It should be unique for the job. It is a mandatory parameter.name: name of the job. It is a mandatory parameter.NOTE: This changed in 2.4.1 releasepipeline_run_id: id of the pipeline_run for which you want to add a job. It is a mandatory parameter ifjobis being created usingpipeline. Its is not needed if job is being created usingpipeline_run.description: description of the jobinputs: (list[Node]) input for the job. This can be uid of an asset specified using asset_uid parameter of Node object
or it can be uid of another job specified using job_uid parameter of Node object.outputs: (list[Node]) output for the job.This can be uid of an asset specified using asset_uid parameter of Node object
or it can be uid of another job specified using job_uid parameter of Node object.meta: Metadata of the Jobcontext: context of the jobbounded_by_span: (Boolean) This has to be set to True if the job has to be bounded with a span. Default value is false. It is an optional parameter.span_uid: (String) This is uid of new span to be created. This is a mandatory parameter if bounded_by_span is set to True.with_explicit_time: An optional boolean parameter used when a job is bounded by a span.If set to True, the child span will be started at the specified time provided in the subsequent events.If not set, the span will be automatically started with the current time at the moment of creation.fromacceldata_sdk.torch_clientimportTorchClientfromacceldata_sdk.models.jobimportCreateJob,JobMetadata,Nodefromacceldata_sdk.models.pipelineimportCreatePipeline,PipelineMetadata,PipelineRunResult,PipelineRunStatus# Create pipelinepipeline=CreatePipeline(uid='monthly_reporting_pipeline',name='Monthly reporting Pipeline',description='Pipeline to create monthly reporting tables',meta=PipelineMetadata('Vaishvik','acceldata_sdk_code','...'),context={'key1':'value1'})torch_client=TorchClient(url="https://torch.acceldata.local",access_key="*******",secret_key="******************************",do_version_check=False)pipeline_response=torch_client.create_pipeline(pipeline=pipeline)pipeline_run=pipeline_response.create_pipeline_run()# Create a job using pipeline object.# Passing of pipeline_run_id is mandatoryjob=CreateJob(uid='monthly_sales_aggregate',name='Monthly Sales Aggregate',description='Generates the monthly sales aggregate tables for the complete year',inputs=[Node(asset_uid='datasource-name.database.schema.table_1')],outputs=[Node(job_uid='job2_uid')],meta=JobMetadata('vaishvik','backend','https://github.com/'),context={'key21':'value21'},bounded_by_span=True,pipeline_run_id=pipeline_run.id,span_uid="test_shubh")job_response=pipeline_response.create_job(job)# Create a job using pipeline_run object.# Passing of pipeline_run_id is not neededjob=CreateJob(uid='monthly_sales_aggregate',name='Monthly Sales Aggregate',description='Generates the monthly sales aggregate tables for the complete year',inputs=[Node(asset_uid='datasource-name.database.schema.table_1')],outputs=[Node(job_uid='job2_uid')],meta=JobMetadata('vaishvik','backend','https://github.com/'),context={'key21':'value21'})job_response_using_run=pipeline_run.create_job(job)Create Pipeline Run And Generate Spans And Send Span EventsPipeline run indicates the execution of the pipeline. The same pipeline can be executed multiple times and each execution (run) has new snapshot version. Each pipeline run has hierarchical span's group. ASpanis a way to group a bunch of metrics, and they are hierarchical. It can be as granular as possible. The APIs will support creating a span object from a pipeline object, and then hierarchical spans are started from parent spans. A Span typically encompasses a process or a task and can be granular. This hierarchical system is powerful enough to model extremely complex pipeline observability flows. Optionally, a span can also be associated with a Job. This way, we can track starting and completion of Job, including the failure tracking. Start and stop are implicitly tracked for a span.Acceldata sdk also has support for create new pipeline run, add spans in it. During the span life cycle, sdk is able to send some customs and standard span events to collect pipeline run metrics for observability.Params forcreate_spanfunction which is available under apipeline_runuid: uid of the span being created. This should be unique. This is a mandatory parameter.associatedJobUids: List of job uids with which the span needs to be associated with.context_data: This is dict of key-value pair providing custom context information related to a span.Params forcreate_child_spanfunction which is available underspan_context. This is used to create hierarchy of span by creating a span under another spanuid: uid of the span being created. This should be unique. This is a mandatory parameter.context_data: This is dict of key-value pair providing custom context information related to a span.associatedJobUids: List of job uids with which the span needs to be associated with.fromacceldata_sdk.events.generic_eventimportGenericEventfromdatetimeimportdatetime# create a pipeline run of the pipelinepipeline_run=pipeline_response.create_pipeline_run()# get root span of a pipeline runroot_span=pipeline_run.get_root_span()# create span in the pipeline runspan_context=pipeline_run.create_span(uid='monthly.generate.data.span')# check current span is root or notspan_context.is_root()# end the spanspan_context.end()# check if the current span has children or notspan_context.has_children()# create a child spanchild_span_context=span_context.create_child_span('monthly.generate.customer.span')# send custom eventchild_span_context.send_event(GenericEvent(context_data={'client_time':str(datetime.now()),'row_count':100},event_uid="order.customer.join.result"))# abort spanchild_span_context.abort()# failed spanchild_span_context.failed()# update a pipeline run of the pipelineupdatePipelineRunRes=pipeline_run.update_pipeline_run(context_data={'key1':'value2','name':'backend'},result=PipelineRunResult.SUCCESS,status=PipelineRunStatus.COMPLETED)Get Latest Pipeline RunAcceldata sdk can get the latest pipeline run of the pipeline. With use of the latest pipeline run instance, user can continue ETL pipeline and add spans, jobs, events too. Hence, Acceldata sdk has complete access on the torch pipeline service.
Params forget_pipeline:pipeline_identity: String parameter used to filter pipeline. It can be either id or uid of the pipeline.pipeline=torch_client.get_pipeline('monthly.reporting.pipeline')pipeline_run=pipeline.get_latest_pipeline_run()Get Pipeline Run with a particular pipeline run idAcceldata sdk can get a pipeline run of the pipeline with a particular pipeline run id. With use of the pipeline run
instance, user can continue ETL pipeline and add spans, jobs, events too. Hence, Acceldata sdk has complete access on the torch pipeline service.Params forget_pipeline_run:pipeline_run_id: run id of the pipeline runcontinuation_id: continuation id of the pipeline runpipeline_id: id of the pipeline to which the run belongs topipeline_run=torch_client.get_pipeline_run(pipeline_run_id=pipeline_run_id)pipeline=torch_client.get_pipeline(pipeline_id=pipeline_id)pipeline_run=torch_client.get_pipeline_run(continuation_id=continuation_id,pipeline_id=pipeline.id)pipeline_run=pipeline.get_run(continuation_id=continuation_id)Get Pipeline details for a particular pipeline run idAcceldata sdk can get Pipeline details for a particular pipeline run.pipeline_details=pipeline_run.get_details()Get all spans for a particular pipeline run idAcceldata sdk can get all spans for a particular pipeline run id.pipeline_run_spans=pipeline_run.get_spans()Get Pipeline Runs for a pipelineAcceldata sdk can get all pipeline runs.
Params forget_pipeline_runs:pipeline_id: id of the pipelineruns=torch_client.get_pipeline_runs(pipeline_id)runs=pipeline.get_runs()Get all PipelinesAcceldata sdk can get all pipelines.pipelines=torch_client.get_pipelines()Delete a PipelineAcceldata sdk can delete a pipeline.delete_response=pipeline.delete()Execute policy synchronously and asynchronouslyAcceldata sdk provides utility functionexecute_policyto execute policies synchronously and asynchronously. This will return an object on whichget_resultandget_statuscan be called to get result and status of the execution respectively.Params forexecute_policy:sync: Boolean parameter used to decide if the policy should be executed synchronously or asynchronously. It is a mandatory parameter. If its is set toTrueit will return only after the execution ends. If it is set toFalseit will return immediately after starting the execution.policy_type: Enum parameter used to specify the policy type. It is a mandatory parameter. It is a enum which will take values from constants as PolicyType.DATA_QUALITY or PolicyType.RECONCILIATION.policy_id: String parameter used to specify the policy id to be executed. It is a mandatory parameter.incremental: Boolean parameter used to specify if the policy execution should be incremental or full. Default value is False.pipeline_run_id: Long parameter used to specify Run id of the pipeline run where the policy is being executed. This can
be used to link the policy execution with a particular pipeline run.failure_strategy: Enum parameter used to decide the behaviour in case of failure. Default value is DoNotFail.failure_strategytakes enum of typeFailureStrategywhich can have 3 values DoNotFail, FailOnError and FailOnWarning.DoNotFail will never throw. In case of failure it will log the error.FailOnError will Throw exception only if it's an error. In case of warning it return without any errors.FailOnWarning will Throw exception on warning as well as error.To get the execution result we can callget_policy_execution_resulton torch_client or callget_resulton execution object which will return a result object.Params forget_policy_execution_result:policy_type: Enum parameter used to specify the policy type. It is a mandatory parameter. It is a enum which will take values from constants as PolicyType.DATA_QUALITY or PolicyType.RECONCILIATION.execution_id: String parameter used to specify the execution id to be queried for rsult. It is a mandatory parameter.failure_strategy: Enum parameter used to decide the behaviour in case of failure. Default value is DoNotFail.Params forget_result:failure_strategy: Enum parameter used to decide the behaviour in case of failure. Default value is DoNotFail.To get the current status we can callget_policy_statuson torch_client or callget_statuson execution object which will get the currentresultStatusof the execution.params forget_policy_status:policy_type: Enum parameter used to specify the policy type. It is a mandatory parameter. It is a enum which will take values from constants as PolicyType.DATA_QUALITY or PolicyType.RECONCILIATION.execution_id: String parameter used to specify the execution id to be queried for rsult. It is a mandatory parameter.get_statusdoes not take any parameter.Asynchronous execution examplefromacceldata_sdk.torch_clientimportTorchClientimportacceldata_sdk.constantsasconsttorch_credentials={'url':'https://torch.acceldata.local:5443/torch','access_key':'PJSAJALFHSHU','secret_key':'E6LLJHKGSHJJTRHGK540E5','do_version_check':'True'}torch_client=TorchClient(**torch_credentials)async_executor=torch_client.execute_policy(const.PolicyType.DATA_QUALITY,46,sync=False,failure_strategy=const.FailureStrategy.DoNotFail,pipeline_run_id=None)# Wait for execution to get final resultexecution_result=async_executor.get_result(failure_strategy=const.FailureStrategy.DoNotFail)# Get the current statusexecution_status=async_executor.get_status()Synchronous execution example.fromacceldata_sdk.torch_clientimportTorchClientimportacceldata_sdk.constantsasconsttorch_credentials={'url':'https://torch.acceldata.local:5443/torch','access_key':'PJSAJALFHSHU','secret_key':'E6LLJHKGSHJJTRHGK540E5','do_version_check':'True'}torch_client=TorchClient(**torch_credentials)# This will wait for execution to get final resultsync_executor=torch_client.execute_policy(const.PolicyType.DATA_QUALITY,46,sync=True,failure_strategy=const.FailureStrategy.DoNotFail,pipeline_run_id=None)# Wait for execution to get final resultexecution_result=sync_executor.get_result(failure_strategy=const.FailureStrategy.DoNotFail)# Get the current statusexecution_status=sync_executor.get_status()Cancel execution example.execution_result=sync_executor.cancel()Example of continuing the same pipeline run across multiple ETL scripts using continuation_idETL1 - Here a new pipeline_run is created using a continuation_id but pipeline_run is not closedfromacceldata_sdk.torch_clientimportTorchClientfromacceldata_sdk.models.pipelineimportCreatePipeline,PipelineMetadata,PipelineRunResult,PipelineRunStatus# Create pipelinepipeline_uid='monthly_reporting_pipeline'pipeline=CreatePipeline(uid=pipeline_uid,name='Monthly reporting Pipeline',description='Pipeline to create monthly reporting tables',meta=PipelineMetadata('Vaishvik','acceldata_sdk_code','...'),context={'key1':'value1'})torch_client=TorchClient(url="https://torch.acceldata.local",access_key="*******",secret_key="******************************",do_version_check=False)pipeline_response=torch_client.create_pipeline(pipeline=pipeline)# A new continuation id should be generated on every run. Same continuation id cannot be reused.cont_id="continuationid_demo_1"pipeline_run=pipeline_response.create_pipeline_run(continuation_id=cont_id)# Make sure pipeline_run is not ended using the update_pipeline_run call so that same run can be used in next ETL scriptETL2 - This script will continue the same pipeline run from ETL1fromacceldata_sdk.torch_clientimportTorchClientfromacceldata_sdk.models.pipelineimportPipelineRunResult,PipelineRunStatustorch_client=TorchClient(url="https://torch.acceldata.local",access_key="*******",secret_key="******************************",do_version_check=False)pipeline_uid='monthly_reporting_pipeline'# First get the same pipeline using the previously used UID. Then we will get the previously started pipeline_run using the continuation_idpipeline=torch_client.get_pipeline(pipeline_uid)# continuation_id should be a same ID used in ETL1 script so that same pipeline_run is continued in the pipeline.cont_id="continuationid_demo_1"pipeline_run=pipeline.get_run(continuation_id=cont_id)# Use this pipeline run to create span and jobs# At the end of this script close the pipeline run using update_pipeline_run if we do not want to continue the same pipeline_run furtherupdatePipelineRunRes=pipeline_run.update_pipeline_run(context_data={'key1':'value2','name':'backend'},result=PipelineRunResult.SUCCESS,status=PipelineRunStatus.COMPLETED)Datasource APIsAcceldata SDK has full access on catalog APIs as well.Datasource APITorch has support for more 15+ datasource crawling support.# Get datasourceds_res=torch_client.get_datasource('snowflake_ds_local')ds_res=torch_client.get_datasource(5,properties=True)# Get datasources based on typedatasources=torch_client.get_datasources(const.AssetSourceType.SNOWFLAKE)Assets APIsAcceldata sdk has methods to get assets in the given datasource.fromacceldata_sdk.models.create_assetimportAssetMetadata# Get asset by id/uidasset=torchclient.get_asset(1)asset=torch_client.get_asset('Feature_bag_datasource.feature_1')Asset's tags, labels, metadata and sample dataUser can add tags, labels custom metadata and also get sample data of the asset using sdk.
Tags and labels can be used to filter out asset easily.# asset metadatafromacceldata_sdk.models.tagsimportAssetLabel,CustomAssetMetadataasset=torch_client.get_asset(asset_id)# Get metadata of an assetasset.get_metadata()# Get all tagstags=asset.get_tags()# Add tag assettag_add=asset.add_tag(tag='asset_tag')# Add asset labelslabels=asset.add_labels(labels=[AssetLabel('test1','demo1'),AssetLabel('test2','demo2')])# Get asset labelslabels=asset.get_labels()# Add custom metadataasset.add_custom_metadata(custom_metadata=[CustomAssetMetadata('testcm1','democm1'),CustomAssetMetadata('testcm2','democm2')])Crawler OperationsUser can start crawler as well as check for running crawler status.# Start a crawlerdatasource.start_crawler()torch_client.start_crawler('datasource_name')# Get running crawler statusdatasource.get_crawler_status()torch_client.get_crawler_status('datasource_name')Trigger policies, Profiling and sampling of an assetCrawled assets can be profiled and sampled with use of spark jobs running on the livy.
Furthermore, Created policies (Recon + DQ) can be triggered too.importacceldata_sdk.constantsasconst# profile an asset, get profile req details, cancel profileprofile_res=asset.start_profile(profiling_type=ProfilingType.FULL)profile_req_details=profile_res.get_status()cancel_profile_res=profile_res.cancel()profile_res=asset.get_latest_profile_status()profile_req_details_by_req_id=torch_client.get_profile_status(asset_id=profile_req_details.assetId,req_id=profile_req_details.id)# sample datasample_data=asset.sample_data()# Rule execution and status# Execute policyexecute_dq_rule=torch_client.execute_policy(const.PolicyType.DATA_QUALITY,1114,incremental=False)failure_strategy=const.FailureStrategy.DoNotFail# Get policy execution resultresult=torch_client.get_policy_execution_result(policy_type=const.PolicyType.DATA_QUALITY,execution_id=execute_dq_rule.id,failure_strategy=failure_strategy)# Get policy and executefromacceldata_sdk.models.ruleExecutionResultimportRuleType,PolicyFilterrule=torch_client.get_policy(const.PolicyType.RECONCILIATION,"auth001_reconciliation")# Execute policyasync_execution=rule.execute(sync=False)# Get execution resultasync_execution_result=async_execution.get_result()# Get current execution statusasync_execution_status=async_execution.get_status()# Cancel policy execution jobcancel_rule=async_execution.cancel()# List all executions# List executions by iddq_rule_executions=torch_client.policy_executions(1114,RuleType.DATA_QUALITY)# List executions by namedq_rule_executions=torch_client.policy_executions('dq-scala',RuleType.DATA_QUALITY)# List executions by rulerecon_rule_executions=rule.get_executions()filter=PolicyFilter(policyType=RuleType.RECONCILIATION,enable=True)# List all rulesrecon_rules=torch_client.list_all_policies(filter=filter)Version Log0.0.1 (12/09/2022)Acceldata python sdkSupport for flow APIs and catalog APIs of the torch