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.
Prerequisites
- A Great Expectations instance. See Install Great Expectations locally.
Steps
1. Import Great Expectations
We will import the Great Expectations module with the command:
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.
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.
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.
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:
- How to configure an Expectation Store on a filesystem
- How to configure a Validation Result Store on a filesystem
- How to configure and use a Metric Store
- How to host and share Data Docs on a filesystem
If you are content with the default configuration of your Data Context, you can move on to connecting GX to your source data:
- How to configure a Pandas Datasource
- How to configure a Spark Datasource
- How to configure a SQL Datasource
Additional information
Related guides
- To initialize and instantiate a temporary Data Context, see: How to instantiate an Ephemeral Data Context