Skip to main content
Version: 0.16.16

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

Steps

1. Import Great Expectations

We will import the Great Expectations module with the command:

Python code
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)
What if the folder does not contain a Data Context?

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.

Python code
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:

If you are content with the default configuration of your Data Context, you can move on to connecting GX to your source data:

Additional information

To initialize and instantiate a temporary Data Context, see: How to instantiate an Ephemeral Data Context.