Skip to main content
Version: 0.16.15

How to quickly instantiate a 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. This guide will demonstrate how to instantiate an existing Filesystem Data Context so that you can continue working with previously defined GX configurations.



1. Import Great Expectations

We will import the Great Expectations module with the command:

Python code
import great_expectations as gx

2. Run GX's get_context(...) method

To quickly acquire a Data Context, we can use the get_context(...) method without any defined parameters.

Python code
context = gx.get_context()

This functions as a convenience method for initializing, instantiating, and returning a Data Context. In the absence of parameters defining its behaviour, calling get_context() will return either a Cloud Data Context, a Filesystem Data Context, or an Ephemeral Data Context depending on what type of Data Context has previously been initialized with your GX install.

If you have GX Cloud configured on your system, get_context() will instantiate and return a Cloud Data Context. Otherwise, get_context() will attempt to instantiate and return the last accessed Filesystem Data Context. Finally, if a previously initialized Filesystem Data Context cannot be found, get_context() will initialize, instantiate, and return a temporary in-memory Ephemeral Data Context.

Saving the contents of an Ephemeral Data Context for future use

An Ephemeral Data Context is an in-memory Data Context that is not intended to persist beyond the current Python session. However, if you decide that you would like to save its contents for future use you can do so by converting it to a Filesystem Data Context:

context = context.convert_to_file_context()

This method will initialize a Filesystem Data Context in the current working directory of the Python process that contains the Ephemeral Data Context. For more detailed explanation of this method, please see our guide on how to convert an ephemeral data context to a filesystem 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

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