Skip to main content
Version: 1.2.2

Create a Data Context

A Data Context defines the storage location for metadata, such as your configurations for Data Sources, Expectation Suites, Checkpoints, and Data Docs. It also contains your Validation Results and the metrics associated with them, and it provides access to those objects in Python, along with other helper functions for the GX Python API.

All scripts that utilize GX Core should start with the creation of a Data Context.

The following are the available Data Context types:

  • File Data Context: A persistent Data Context that stores metadata and configuration information as YAML files within a file system. File Data Contexts allow you to re-use previously configured Expectation Suites, Data Sources, and Checkpoints.

  • Ephemeral Data Context: A temporary Data Context that stores metadata and configuration information in memory. This Data Context will not persist beyond the current Python session. Ephemeral Data Contexts are useful when you don’t have write permissions to a file system or if you are going to engage in data exploration without needing to save your results.

  • GX Cloud Data Context: A Data Context that connects to a GX Cloud Account to retrieve and store GX Cloud metadata and configuration information. The GX Cloud Data Context lets you leverage GX Cloud to share your Expectation Suites, Data Sources, and Checkpoints with your organization.

Prerequisites

Request an available Data Context

  1. Run the following code to request a Data Context:

    Python input
    import great_expectations as gx

    context = gx.get_context()

    If you don't specify parameters with the get_context() method, GX checks your project environment and returns the first Data Context using the following criteria:

    • get_context() instantiates and returns a GX Cloud Data Context if it finds the necessary credentials in your environment variables.
    • If a GX Cloud Data Context cannot be instantiated, get_context() will instantiate and return the first File Data Context it finds in the folder hierarchy of your current working directory.
    • If neither of the above options are viable, get_context() instantiates and returns an Ephemeral Data Context.
  2. Optional. Run the following code to verify the type of Data Context you received:

    Python input
    print(type(context).__name__)

    The name of the Data Context class is displayed.