Skip to content
SupportLogin
Adaptive Data
Edit on GitHub

Create a dataset

Upload a local file or import a dataset from Hugging Face or Kaggle with the Python SDK.

Import data from a local file, Hugging Face, or Kaggle without writing a conversion script. Each method returns a dataset_id that you pass to datasets.adapt.

The examples assume you have installed the Python SDK and set ADAPTION_API_KEY:

from adaption import Adaption
client = Adaption()
1. Upload a local file

The SDK helper creates the dataset, uploads the file, and confirms the upload.

Supported extensions: .csv, .json, .jsonl, and .parquet. Documents (.pdf, .docx, .pptx, .xlsx, .html, .txt, and .zip) upload the same way but need an extraction step first; see Upload documents.

dataset = client.datasets.upload_file("training_data.csv")
dataset_id = dataset.dataset_id
print(dataset_id)
2. Import from Hugging Face

Point at a Hugging Face dataset URL and the file(s) to import.

dataset = client.datasets.create(
source={
"url": "https://huggingface.co/datasets/tatsu-lab/alpaca",
"files": [
"data/train-00000-of-00001-a09b74b3ef9c3b56.parquet"
],
},
)
dataset_id = dataset.dataset_id
print(dataset_id)
3. Import from Kaggle

Use the Kaggle dataset page URL and the files to pull.

dataset = client.datasets.create(
source={
"url": "https://www.kaggle.com/datasets/uciml/sms-spam-collection-dataset",
"files": ["spam.csv"],
},
)
dataset_id = dataset.dataset_id
print(dataset_id)

Kaggle credentials must be registered in Adaption: open API keys settings (sign in if prompted) and add your Kaggle API credentials there before importing.

Documents are not rows yet. After the upload, Adaption counts their pages and waits for you to launch extraction, which turns the content into rows and costs credits.

Upload the file and wait for it to finish. The dataset stops at awaiting_input with no row_count:

dataset = client.datasets.upload_file("annual_report.pdf")
dataset_id = dataset.dataset_id
status = client.datasets.wait_for_completion(dataset_id)
print(status.status, status.row_count)

Check what extraction will cost before you launch it with get_preprocessing_credits. Pages are counted in the background, so the dataset can reach awaiting_input before the count is done. Until then the quote is partial (is_final is False), so poll until it is final:

import time
quote = client.datasets.get_preprocessing_credits(dataset_id)
while not quote.is_final:
time.sleep(2)
quote = client.datasets.get_preprocessing_credits(dataset_id)
print(f"{quote.total_pages:.0f} pages cost {quote.extraction_cost} credits")
print(f"{quote.available_credits} credits available")
if quote.insufficient_credits:
raise RuntimeError("Not enough credits to extract these documents")

Launch extraction with launch_preprocessing, then wait again. When extraction finishes, the dataset returns to awaiting_input, this time with a row_count:

launch = client.datasets.launch_preprocessing(
dataset_id,
preprocessing_mode="per_page",
)
print(f"Reserved {launch.credits_escrowed} credits")
status = client.datasets.wait_for_completion(dataset_id)
if status.status == "failed":
error = status.error_data
message = (error and error.message) or "unknown error"
raise RuntimeError(f"Document extraction failed: {message}")
print(f"Extracted {status.row_count} rows")

preprocessing_mode decides how content becomes rows: per_document (the default) makes one row per document, per_page one row per page. To extract only part of the upload, pass either pages_to_process or documents_to_process, not both. get_preprocessing_credits accepts the same limits, so you can quote a subset before launching it.

Imports run asynchronously. Poll the dataset status until ingestion has populated the dataset before starting an adaptation run:

import time
while True:
status = client.datasets.get_status(dataset_id)
if status.status == "failed":
error = status.error_data
message = (error and error.message) or "unknown error"
raise RuntimeError(f"Dataset import failed: {message}")
if status.row_count is not None:
print(f"Imported {status.row_count} rows")
break
time.sleep(5)

Next, map the imported columns, then configure the adaptation run. For endpoint details, see the create and get_status references. The datasets.upload_file helper handles the create, upload, and completion steps for local files.