Skip to main content
In this notebook we will demonstrate how the DataFramer Python SDK (PIP Package: pydataframer) can be used to generate large amounts of high quality synthetic datasets where each sample size can be arbitrarily large.

Prerequisites

Import this notebook into your Databricks workspace and run it there. To run it in Google Colab or a local Jupyter instead, see Running it outside Databricks below.
  1. Table access (one-time admin setup)
    Whoever runs this notebook — a person, or a service principal when it runs as a job — needs:
    • USE CATALOG on the catalog
    • USE SCHEMA and SELECT on the schema it reads the sample data from
    • USE SCHEMA, CREATE TABLE, MODIFY and APPLY TAG on the schema it writes results to
    • CAN USE on the SQL warehouse
  2. DataFramer Databricks Credentials (one-time admin setup)
    A DataFramer company admin must configure the Databricks service principal credentials in the DataFramer web application. Navigate to Settings > Keys, choose the provider Databricks, and enter:
    • Client ID — the service principal application (client) ID
    • Client Secret — the service principal secret
    • Workspace URL — the workspace’s address
      (e.g. https://dbc-xxxxx.cloud.databricks.com)
    Once saved, every AI task of every team member runs on Databricks: databricks/ models run as chosen, and a model chosen from another provider is moved to its Databricks equivalent. A company holds one provider credential at a time, so saving the Databricks credential replaces an Anthropic or OpenAI key. No credentials need to be passed in API calls.
  3. DataFramer API key
    Retrieve it from Settings > Keys > Copy API Key on the web application. Store it in a Databricks secret scope; this example uses a scope named dataframer with the key DATAFRAMER_API_KEY. Whoever runs this notebook needs at least READ permission on that scope — including the service principal, when it runs as a job.

Running it outside Databricks

There is no workspace identity and no secret scope, so pass the values in directly. The SQL warehouse’s HTTP path is on its Connection details tab.
Keep the client secret out of any notebook you share or commit.

Step 1: Install and Setup SDK

Install the DataFramer SDK and the Databricks connector package for DataFramer.

Initialize the DataFramer client and the DatabricksConnector

In this step, we initialize the DataFramer client with the API key stored in the dataframer secret scope, and the DatabricksConnector, which reaches Unity Catalog as the identity running this notebook.

Fetch sample data

For this demo, we use sample data available in the Databricks catalog, specifically the samples.bakehouse.media_customer_reviews table. To keep the example lightweight, we select only the top 25 rows, export them as a CSV file, and upload the file to DataFramer.

Step 2: Upload data

Prepare CSV and upload to DataFramer

To use DataFramer, only a small sample of data is needed. To derive these samples from a table, we recommend creating a CSV file that contain the relevant rows from the table and supplying that as a Seed dataset to DataFramer.

Retrieve Dataset Details

This API demonstrates how to retrieve a specific dataset given a dataset ID.

Step 3: Generate Specification via the analysis API

A specification (or “spec”) is a detailed description that captures the structure, patterns, and requirements of your data. Think of a spec as a blueprint for your data generation task. DataFramer automatically generates specifications by analyzing your seed data. This cell ensures a specification exists for the dataset by reusing an existing one or generating a new one. When using a databricks/ model, DataFramer automatically retrieves your company’s stored Databricks credentials (configured by your admin in Settings > Keys).

Review Generated Specification

This cell retrieves the latest version of the generated specification and inspects key properties inferred from the dataset, such as data property variations.

Step 4: Update Specification (Optional)

This cell demonstrates how to programmatically update a given specification. To keep this demo simple, the update is applied only when the specification is newly created (i.e., when the latest version is 1). If the specification has already been updated, this step is skipped. In this step, we add a new data property called Review Detail Level with values 'Very brief', 'Brief', 'Moderate', 'Detailed' and expected distributions [15, 30, 35, 20].

Step 5: Generate New Samples

Once the spec is generated and finalized after any manual modifications, we will use this spec to generate synthetic data. Databricks credentials are retrieved automatically from your company’s stored configuration.

Step 6: Evaluate Generated Samples

While DataFramer evaluates each sample as it is generated, it also supports a post-generation evaluation. This API shows how to evaluate the generated dataset. Read the documentation for more details.

Step 7: Download Generated Files

List Generated Files

This API lists all the files that were present in the generated dataset.

Download All Files as ZIP

This API allows you to download all the generated files with metadata as a compressed ZIP file.

Load generated data into a Delta table

This cell writes the generated data into a Delta table <catalog>.<schema>.<table_name>. If the table already exists, its contents are overwritten.