Manage Checkpoints
You can use Checkpoints to group Validation Definitions and run them with shared parameters and automated Actions.
At runtime, a Checkpoint can take in dictionaries that filter the Batches in each Validation Definition and modify the parameters of the Expectations that will be validated against them. The parameters apply to every Validation Definition in the Checkpoint. Therefore, the Validation Definitions grouped in a Checkpoint should have Batch Definitions that accept the same Batch filtering criteria. In addition, the Expectation Suites in each Validation Definition should also share a list of valid parameters.
After a Checkpoint receives Validation Results from a Validation Definition, it executes a list of Actions. The returned Validation Results determine what task is performed for each Action. Actions can include updating Data Docs with the new Validation Results or sending alerts when validations fail. The Actions list is executed once for each Validation Definition in a Checkpoint.
If the list of Actions for a Checkpoint is empty, the Checkpoint can still run. Its validation results are saved to the Data Context, but no tasks are executed.
Create a Checkpoint
- Procedure
- Sample code
- Import the GX library and the
Checkpoint
class:
import great_expectations as gx
from great_expectations.core import Checkpoint
In this example the variable context
is your Data Context.
- Get the Validation Definition or Definitions to add to the Checkpoint.
In this example the variable validation_definitions
is a list object containing a single Validation Definition.
- Optional. Determine the Actions to add to the Checkpoint.
In this example, the variable actions
is a list of two actions. The first updates your Data Docs with the results of the Validation Definition. The second sends a Slack notification if any of the Expectations in the Validation Definition failed:
actions = [gx.UpdateDataDocs(...), gx.SlackNotification(...)]
A list of available Actions is available with the Checkpoint class in the GX API documentation.
- Create the Checkpoint:
checkpoint_name = "my_checkpoint"
checkpoint = Checkpoint(
name=checkpoint_name, validations=validation_definitions, actions=actions
)
- Add the Checkpoint to the Data Context:
context.checkpoints.add(checkpoint)
import great_expectations as gx
from great_expectations.core import Checkpoint
context = gx.get_context()
validation_definition_name = "my_existing_validation_definition"
validation_definition = context.validation_definitions.get(
name=validation_definition_name
)
validation_definitions = [validation_definition]
actions = [gx.UpdateDataDocs(...), gx.SlackNotification(...)]
checkpoint_name = "my_checkpoint"
checkpoint = Checkpoint(
name=checkpoint_name, validations=validation_definitions, actions=actions
)
context.checkpoints.add(checkpoint)
List available Checkpoints
- Procedure
- Sample code
In this example the variable context
is your Data Context.
- Use the Data Context to retrieve and print the names of the available Checkpoints:
checkpoint_names = [checkpoint.name for checkpoint in context.checkpoints]
print(checkpoint_names)
import great_expectations as gx
context = gx.get_context()
checkpoint_names = [checkpoint.name for checkpoint in context.checkpoints]
print(checkpoint_names)
Get a Checkpoint by name
- Procedure
- Sample code
In this example the variable context
is your Data Context.
- Use the Data Context to request the Checkpoint:
checkpoint_name = "my_checkpoint"
checkpoint = context.checkpoints.get(name=checkpoint_name)
import great_expectations as gx
context = gx.get_context()
checkpoint_name = "my_checkpoint"
checkpoint = context.checkpoints.get(name=checkpoint_name)
Get Checkpoints by attributes
- Procedure
- Sample code
In this example the variable context
is your Data Context.
- Determine the filter attributes.
Checkpoints associate a list of one or more Validation Definitions with a list of Actions to perform. The attributes used to filter the results include the attributes for the Validation Definitions, their Batch Definitions and Expectation Suites, and the Checkpoint Actions.
- Use a list comprehension to return all Checkpoints that match the filtered attributes.
For example, you can retrieve all Checkpoints that send alerts through Slack by filtering on the Actions of each Checkpoint:
checkpoints_with_slack_alerts = [
checkpoint.name
for checkpoint in context.checkpoints
if any(isinstance(action, SlackNotificationAction) for action in checkpoint.actions)
]
print(checkpoints_with_slack_alerts)
import great_expectations as gx
from great_expectations.checkpoints import SlackNotificationAction
context = gx.get_context()
checkpoints_with_slack_alerts = [
checkpoint.name
for checkpoint in context.checkpoints
if any(isinstance(action, SlackNotificationAction) for action in checkpoint.actions)
]
print(checkpoints_with_slack_alerts)
Update a Checkpoint
- Procedure
- Sample code
In this example the variable context
is your Data Context.
In this example the variable checkpoint
is the Checkpoint that is updated.
- Overwrite the Checkpoint values with updated lists.
In this example, the Checkpoint Validation Definitions and Actions receive updates:
new_validations_list = [context.validation_definitions.get(name="new_validation")]
new_actions_list = [gx.UpdateDataDocs(...)]
checkpoint.validations = new_validations_list
checkpoint.actions = new_actions_list
- Save the changes to the Data Context:
checkpoint.save()
import great_expectations as gx
context = gx.get_context()
checkpoint_name = "my_checkpoint"
checkpoint = context.checkpoints.get(name=checkpoint_name)
new_validations_list = [context.validation_definitions.get(name="new_validation")]
new_actions_list = [gx.UpdateDataDocs(...)]
checkpoint.validations = new_validations_list
checkpoint.actions = new_actions_list
checkpoint.save()
Delete a Checkpoint
- Procedure
- Sample code
In this example the variable context
is your Data Context.
- Use the Data Context to delete the Checkpoint:
checkpoint_name = "my_checkpoint"
context.checkpoints.delete(name=checkpoint_name)
import great_expectations as gx
context = gx.get_context()
checkpoint_name = "my_checkpoint"
context.checkpoints.delete(name=checkpoint_name)
Run a Checkpoint
🚧 Under construction 🚧
Updates for this page are in progress.