Skip to main content
Version: 0.16.8

Datasource

In progress

Great Expectations is aware that the fluent datasource and yaml config workflows are undocumented. A new method for connecting to data sources will be added to this topic soon. In the meantime, use the Great Expectations Slack channel if you encounter issues and need assistance.

SetupArrowConnect to DataArrowCreate ExpectationsArrowValidate Data

Definition

A Datasource provides a standard API for accessing and interacting with data from a wide variety of source systems.

Features and promises

Datasources provide a standard API across multiple backends: the Datasource API remains the same for PostgreSQL, CSV Filesystems, and all other supported data backends.

Important:

Datasources do not modify your data.

Relationship to other objects

Datasources function by bringing together a way of interacting with Data (an Execution EngineA system capable of processing data to compute Metrics.) with a way of accessing that data (a Data Connector.Provides the configuration details based on the source data system which are needed by a Datasource to define Data Assets.). Batch RequestsProvided to a Datasource in order to create a Batch. utilize Datasources in order to return a BatchA selection of records from a Data Asset. of data.

Use Cases

Setup

Connect to Data

When connecting to data the Datasource is your primary tool. At this stage, you will create Datasources to define how Great Expectations can find and access your Data AssetsA collection of records within a Datasource which is usually named based on the underlying data system and sliced to correspond to a desired specification.. Under the hood, each Datasource uses an Execution Engine (ex: SQLAlchemy, Pandas, and Spark) to connect to and query data. Once a Datasource is configured you will be able to operate with the Datasource's API rather than needing a different API for each possible data backend you may be working with.

Setup

Create Expectations

When creating ExpectationsA verifiable assertion about data. you will use your Datasources to obtain BatchesA selection of records from a Data Asset. for ProfilersGenerates Metrics and candidate Expectations from data. to analyze. Datasources also provide Batches for Expectation SuitesA collection of verifiable assertions about data., such as when you use the interactive workflow to create new Expectations.

Setup

Validate Data

Datasources are also used to obtain Batches for ValidatorsUsed to run an Expectation Suite against data. to run against when you are validating data.

Features

Standard API

Datasources support connecting to a variety of different data backends. No matter which source data system you employ, the Datasource's API will remain the same.

No Unexpected Modifications

Datasources do not modify your data during profiling or validation, but they may create temporary artifacts to optimize computing Metrics and Validation (this behavior can be configured).

API Basics

How to create and access

Datasources can be created and accessed using Python code, which can be executed from a script, a Python console, or a Jupyter Notebook. To access a Datasource all you need is a Data ContextThe primary entry point for a Great Expectations deployment, with configurations and methods for all supporting components. and the name of the Datasource. The below snippet shows how to create a Pandas Datasource for local files:

import great_expectations as gx

context = gx.get_context()
context.sources.add_pandas_filesystem(
name="my_pandas_datasource", base_directory=data_directory
)

This next snippet shows how to retrieve the Datasource from the Data Context.

datasource = context.datasources["my_pandas_datasource"]
print(datasource)

For detailed instructions on how to create Datasources that are configured for various backends, see our documentation on Connecting to Data.