How to instantiate a specific Filesystem Data Context
A Data ContextThe primary entry point for a Great Expectations deployment, with configurations and methods for all supporting components. contains the configurations for ExpectationsA verifiable assertion about data., Metadata StoresA connector to store and retrieve information about metadata in Great Expectations., Data DocsHuman readable documentation generated from Great Expectations metadata detailing Expectations, Validation Results, etc., CheckpointsThe primary means for validating data in a production deployment of Great Expectations., and all things related to working with Great Expectations.
If you are using GX for multiple projects you may wish to utilize a different Data Context for each one. This guide will demonstrate how to instantiate a specific Filesystem Data Context so that you can switch between sets of previously defined GX configurations.
Prerequisites
- A Great Expectations instance. See Install Great Expectations locally.
- A previously initialized Filesystem Data Context. See How to initialize a Filesystem Data Context in Python.
Steps
1. Import Great Expectations
We will import the Great Expectations module with the command:
import great_expectations as gx
2. Specify a folder containing a previously initialized Filesystem Data Context
Each Filesystem Data Context has a root folder in which it was initialized. This root folder will be used to indicate which specific Filesystem Data Context should be instantiated.
path_to_context_root_folder = "/my_gx_project/"
2. Run GX's
get_context(...)
method
We provide our Filesystem Data Context's root
folder path to the GX library's
get_context(...)
method as the
context_root_dir
parameter. Because we
are providing a path to an existing Data Context, the
get_context(...)
method will instantiate
and return the Data Context at that location.
context = gx.get_context(context_root_dir=path_to_context_root_folder)
If the context_root_dir
provided to
the get_context(...)
method points to
a folder that does not already have a Data Context
present, the get_context(...)
method
will initialize a new Filesystem Data Context at
that location.
The get_context(...)
method will then
instantiate and return the newly initialized Data
Context.
3. Verify the content of the returned Data Context
We can ensure that the Data Context was instantiated correctly by printing its contents.
print(context)
This will output the full configuration of the Data Context in the format of a Python dictionary.
Next steps
For guidance on further customizing your Data Context's configurations for Metadata Stores and Data Docs, please see:
- How to configure an Expectation Store on a filesystem
- How to configure a Validation Result Store on a filesystem
- How to configure and use a Metric Store
- How to host and share Data Docs on a filesystem
If you are content with the default configuration of your Data Context, you can move on to connecting GX to your source data:
- How to configure a Pandas Datasource
- How to configure a Spark Datasource
- How to configure a SQL Datasource
Additional information
Related guides
To initialize and instantiate a temporary Data Context, see: How to instantiate an Ephemeral Data Context.