Open in Google Colab
Run this exact tutorial interactively in Google Colab
pydataframer) can be used to generate large amounts of high quality synthetic datasets for multi-file and multi-folder use cases, where each generated sample can consist of multiple files or an entire folder structure.
Multi-file datasets contain multiple independent files (e.g., a collection of PDF lab reports), while multi-folder datasets organize files into folder hierarchies (e.g., per-patient folders each containing multiple documents). In both cases, seed data is uploaded as a ZIP archive and generated outputs are saved to a Databricks Volume.
Prerequisites
-
Service Principal Permissions (one-time admin setup)
This notebook must be run using a service principal that has access to the required Unity Catalog objects.
A Databricks admin should create a service principal and grant it:USE CATALOGon the catalogUSE SCHEMA,CREATE TABLE,SELECT, andMODIFYon the schemaREAD VOLUMEandWRITE VOLUMEon the volume
- In addition, any user that is using the Databricks UI to access or manage the tables used in this notebook, should be given the same set of permissions specified in Step 1.
-
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 Profile > Keys > Databricks Credentials and enter:- Client ID — the service principal application (client) ID
- Client Secret — the service principal secret
- API Base URL — the Databricks Model Serving endpoint URL
(e.g.https://adb-xxx.azuredatabricks.net/serving-endpoints)
databricks/model for specs, runs, evaluations, or chat. No credentials need to be passed in API calls. -
A Dataframer API key is required for this demo. This can be retrieved by navigating to Profile > Keys > Copy API Key on the web application.
Note that you can use the fully hosted Dataframer solution or an on-prem deployed version (reach out to [email protected] for more details). -
Databricks Secrets Setup
This notebook expects the following secrets to be stored in a Databricks secret scope.
End-users running this notebook need at least READ permission on the secret scope.
In this example, we use a scope nameddataframer.DATAFRAMER_API_KEY— DataFramer API key (from step 4)DATABRICKS_HTTP_PATH— SQL warehouse HTTP path (for data access)DATABRICKS_CLIENT_ID— Service principal client ID (for data access)DATABRICKS_CLIENT_SECRET— Service principal secret (for data access)DATABRICKS_SERVER_HOSTNAME— Databricks workspace hostname (for data access)
The Databricks secrets being stored in a secret scope above are used by the
DatabricksConnector for SQL access (fetching sample data and loading generated data into tables). Model Serving authentication is handled automatically by DataFramer using the credentials configured in step 3.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 using an API key stored securely in Databricks Secrets under thedataframer scope. We also initialize the DatabricksConnector with dataframer scope to access/persist data from/into Unity Catalog.
Step 2: Upload data to DataFramer
For multi-file and multi-folder datasets, seed data must be uploaded as a ZIP archive stored in a Databricks Volume. The ZIP should contain all the sample files (for multi-file) or folder structures (for multi-folder) that DataFramer will analyze to generate new synthetic data.Multi-file upload
A multi-file ZIP contains multiple independent files at the top level (e.g., several PDF lab reports).Multi-folder upload
A multi-folder ZIP contains top-level folders, each with its own set of files (e.g., per-patient folders with lab reports, notes, and imaging results).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 aspec 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 Profile > 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 is1). If the specification has already been updated, this step is skipped. In this step, we add a new data property called Patient Risk Category with values 'Low', 'Moderate', 'High', 'Critical' and expected distributions [25, 40, 25, 10].

