Skip to main content
Version: 0.16.16

util.py

great_expectations.util.get_context(project_config: DataContextConfig | Mapping | None = None, context_root_dir: PathStr = None, runtime_environment: dict | None = None, cloud_base_url: None = None, cloud_access_token: None = None, cloud_organization_id: None = None, cloud_mode: Literal[False] | None = None, ge_cloud_base_url: None = None, ge_cloud_access_token: None = None, ge_cloud_organization_id: None = None, ge_cloud_mode: Literal[False] | None = None) FileDataContext
great_expectations.util.get_context(project_config: DataContextConfig | Mapping | None = None, context_root_dir: None = None, runtime_environment: dict | None = None, cloud_base_url: str | None = None, cloud_access_token: str | None = None, cloud_organization_id: str | None = None, cloud_mode: Literal[True] = None, ge_cloud_base_url: str | None = None, ge_cloud_access_token: str | None = None, ge_cloud_organization_id: str | None = None, ge_cloud_mode: bool | None = None) CloudDataContext
great_expectations.util.get_context(project_config: DataContextConfig | Mapping | None = None, context_root_dir: PathStr | None = None, runtime_environment: dict | None = None, cloud_base_url: str | None = None, cloud_access_token: str | None = None, cloud_organization_id: str | None = None, cloud_mode: bool | None = None, ge_cloud_base_url: str | None = None, ge_cloud_access_token: str | None = None, ge_cloud_organization_id: str | None = None, ge_cloud_mode: bool | None = None) AbstractDataContext

Method to return the appropriate Data Context depending on parameters and environment.

Usage:

import great_expectations as gx

my_context = gx.get_context(<insert_your_parameters>)

This method returns the appropriate Data Context based on which parameters you’ve passed and / or your environment configuration:

  • FileDataContext: Configuration stored in a file.

  • EphemeralDataContext: Configuration passed in at runtime.

  • CloudDataContext: Configuration stored in Great Expectations Cloud.

Read on for more details about each of the Data Context types:

FileDataContext: A Data Context configured via a yaml file. Returned by default if you have no cloud configuration set up and pass no parameters. If you pass context_root_dir, we will look for a great_expectations.yml configuration there. If not we will look at the following locations:

  • Path defined in a GX_HOME environment variable.

  • The current directory.

  • Parent directories of the current directory (e.g. in case you invoke the CLI in a sub folder of your Great Expectations directory).

Relevant parameters

  • context_root_dir: Provide an alternative directory to look for GX config.

  • project_config: Optionally override the configuration on disk - only if context_root_dir is also provided.

  • runtime_environment: Optionally override specific configuration values.

EphemeralDataContext: A temporary, in-memory Data Context typically used in a pipeline. The default if you pass in only a project_config and have no cloud configuration set up.

Relevant parameters

  • project_config: Used to configure the Data Context.

  • runtime_environment: Optionally override specific configuration values.

CloudDataContext: A Data Context whose configuration comes from Great Expectations Cloud. The default if you have a cloud configuration set up. Pass cloud_mode=False if you have a cloud configuration set up and you do not wish to create a CloudDataContext.

Cloud configuration can be set up by passing cloud_* parameters to get_context(), configuring cloud environment variables, or in a great_expectations.conf file.

Relevant parameters

  • cloud_base_url: Override env var or great_expectations.conf file.

  • cloud_access_token: Override env var or great_expectations.conf file.

  • cloud_organization_id: Override env var or great_expectations.conf file.

  • cloud_mode: Set to True or False to explicitly enable/disable cloud mode.

  • project_config: Optionally override the cloud configuration.

  • runtime_environment: Optionally override specific configuration values.

Parameters
  • project_config – In-memory configuration for Data Context.

  • context_root_dir (str or pathlib.Path) – Path to directory that contains great_expectations.yml file

  • runtime_environment – A dictionary of values can be passed to a DataContext when it is instantiated. These values will override both values from the config variables file and from environment variables.

  • cloud_base_url – url for GX Cloud endpoint.

  • cloud_access_token – access_token for GX Cloud account.

  • cloud_organization_id – org_id for GX Cloud account.

  • cloud_mode – whether to run GX in Cloud mode (default is None). If None, cloud mode is assumed if cloud credentials are set up. Set to False to override.

  • ge_cloud_base_url

    url for GX Cloud endpoint.

    Deprecated since version 0.15.37.

  • ge_cloud_access_token

    access_token for GX Cloud account.

    Deprecated since version 0.15.37.

  • ge_cloud_organization_id

    org_id for GX Cloud account.

    Deprecated since version 0.15.37.

  • ge_cloud_mode

    whether to run GX in Cloud mode (default is None). If None, cloud mode is assumed if cloud credentials are set up. Set to False to override.

    Deprecated since version 0.15.37.

Returns

A Data Context. Either a FileDataContext, EphemeralDataContext, or CloudDataContext depending on environment and/or parameters.

Raises

GXCloudConfigurationError – Cloud mode enabled, but missing configuration.