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
Import this notebook into your Databricks workspace and run it there. It reads and writes files in a Databricks Volume, so it cannot run in Google Colab or a local Jupyter.-
Volume access (one-time admin setup)
Whoever runs this notebook — a person, or a service principal when it runs as a job — needs:USE CATALOGon the catalogUSE SCHEMAon the schemaREAD VOLUMEandWRITE VOLUMEon the volume
-
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)
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. -
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 nameddataframerwith the keyDATAFRAMER_API_KEY. Whoever runs this notebook needs at least READ permission on that scope — including the service principal, when it runs as a job.
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 thedataframer secret scope, and the DatabricksConnector, which reaches Unity Catalog as the identity running this notebook.
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 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 is1). If the specification has already been updated, this step is skipped. In this step, we take the first property the spec found in your documents that has no conditional distributions, and make its first value appear in 60% of the generated samples. A property you add yourself must fit your documents: one that does not makes every sample fail generation’s consistency check.

