Convert an Ephemeral Data Context to a Filesystem Data Context
An Ephemeral Data Context is a temporary, in-memory Data Context that will not persist beyond the current Python session. However, if you decide you would like to save the contents of an Ephemeral Data Context for future use you can do so by converting it to a Filesystem Data Context.
Prerequisites
- A working installation of Great Expectations
- An Ephemeral Data Context instance
Confirm your Data Context is Ephemeral
To confirm that you're working with an Ephemeral Data Context, run the following code:
from great_expectations.data_context import EphemeralDataContext
# ...
if isinstance(context, EphemeralDataContext):
print("It's Ephemeral!")
In the example code, it is assumed that your Data
Context is stored in the variable
context
.
Verify that your current working directory does not already contain a GX Filesystem Data Context
The method for converting an Ephemeral Data Context to a Filesystem Data Context initializes the new Filesystem Data Context in the current working directory of the Python process that is being executed. If a Filesystem Data Context already exists at that location, the process will fail.
You can determine if your current working directory
already has a Filesystem Data Context by looking for a
great_expectations.yml
file. The presence
of that file indicates that a Filesystem Data Context
has already been initialized in the corresponding
directory.
Convert the Ephemeral Data Context into a Filesystem Data Context
Converting an Ephemeral Data Context into a Filesystem Data Context can be done with one line of code:
context = context.convert_to_file_context()
The convert_to_file_context()
method
does not change the Ephemeral Data Context itself.
Rather, it initializes a new Filesystem Data
Context with the contents of the Ephemeral Data
Context and then returns an instance of the new
Filesystem Data Context. If you do not replace the
Ephemeral Data Context instance with the
Filesystem Data Context instance, it will be
possible for you to continue using the Ephemeral
Data Context.
If you do this, it is important to note that
changes to the Ephemeral Data Context
will not be reflected in the
Filesystem Data Context. Moreover,
convert_to_file_context()
does not
support merge operations. This means you will not
be able to save any additional changes you have
made to the content of the Ephemeral Data Context.
Neither will you be able to use
convert_to_file_context()
to replace
the Filesystem Data Context you had previously
created:
convert_to_file_context()
will fail
if a Filesystem Data Context already exists in the
current working directory.
For these reasons, it is strongly advised that once you have converted your Ephemeral Data Context to a Filesystem Data Context you cease working with the Ephemeral Data Context instance and begin working with the Filesystem Data Context instance instead.