Skip to main content
Version: 0.18.9

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 (GX). Use the information provided here to instantiate a Data Context so that you can continue working with previously defined GX configurations.

Existing Filesystem

Instantiate an existing Filesystem Data Context so that you can continue working with previously defined GX configurations.

Prerequisites

Import GX

Run the following command to import the GX module:

Python code
import great_expectations as gx

Run the get_context(...) method

To quickly acquire a Data Context, 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 behavior, calling get_context() returns 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() instantiates and returns a Cloud Data Context. Otherwise, get_context() instantiates and returns the last accessed Filesystem Data Context. If a previously initialized Filesystem Data Context cannot be found, get_context() initializes, instantiates, and returns 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:

Python
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

Verify Data Context content

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