How to configure notebooks generated by suite-edit
This guide shows how to customize the Jupyter Notebooks generated by great_expectations suite edit
Prerequisites: This how-to guide assumes you have:
- Completed the Getting Started Tutorial
- A working installation of Great Expectations
The Jupyter Notebooks generated by great_expectations suite edit
are made of different sections:
- header_markdown
- footer_markdown
- table_expectations_header_markdown
- column_expectations_header_markdown
- table_expectations_not_found_markdown
- column_expectations_not_found_markdown
- authoring_intro_markdown
- column_expectations_markdown
- header_code
- footer_code
- column_expectation_code
- table_expectation_code
Each one of those cells expects either Markdown or code. Great Expectations has defaults for each one of those sections, but it supports each section to be overwritten. The default class supports using Jinja templating for dynamic rendering.
Additionally, the class that generates the Jupyter Notebooks can be overwritten.
Overwriting the class
In great_expectations.yml
add
notebooks:
suite_edit:
class_name: CustomeSuiteEditNotebookRender
module_name: custom_plugin.render.renderer.suite_edit_notebook_renderer
Overwriting a section
For markdown
notebooks:
suite_edit:
custom_templates_module: notebook_assets.suite_edit
header_markdown:
file_name: HEADER.md
template_kwargs:
company_name: MyCompany
In this case, Great Expectations will overwrite the header_markdown
section with the file HEADER.md
, which contains the Jinja variable company_name
.
The file should be in your package notebook_assets.suite_edit
.
For example:
great_expectations/plugins/notebook_assets/suite_edit/HEADER.md:
# Custom header for {{ company_name }}
For code
notebooks:
suite_edit:
custom_templates_module: notebook_assets.suite_edit
footer_code:
file_name: footer.py
template_kwargs:
site_name: site_local
validation_operator_name: local
In this case, Great Expectations will overwrite the footer_code
section with the file footer.py
, which contains the Jinja variables site_name
, and validation_operator_name
.
The file should be in your package notebook_assets.suite_edit
.
For example:
great_expectations/plugins/notebook_assets/suite_edit/footer.py:
batch.save_expectation_suite(discard_failed_expectations=False)
run_id = {
"run_name": "some_string_that_uniquely_identifies_this_run", # insert your own run_name here
"run_time": datetime.datetime.now(datetime.timezone.utc),
}
results = context.run_validation_operator(
"{{ validation_operator_name }}", assets_to_validate=[batch], run_id=run_id
)
validation_result_identifier = results.list_validation_result_identifiers()[0]
context.build_data_docs(site_names=["{{ site_name }}"])
context.open_data_docs(validation_result_identifier, site_name="{{ site_name }}")
Notes
The template_kwargs
argument is optional, so the provided files do not have to contain Jinja templating.