Getting started
Turn a messy spreadsheet into a clean SQLite database.
In this tutorial, you’ll upload a spreadsheet, convert it into a structured sheet, and download it as a SQLite database and individual CSV files.
Prerequisites
Section titled “Prerequisites”- Python 3.9+ or Node.js 20+
- A DeepTable API key (get one at deeptable.com)
1. Install the SDK
Section titled “1. Install the SDK”pip install deeptablenpm install @deeptable/deeptable2. Set your API key
Section titled “2. Set your API key”export DEEPTABLE_API_KEY="your-api-key"3. Download an example spreadsheet
Section titled “3. Download an example spreadsheet”curl -O https://docs.deeptable.com/acme_subscriptions.xlsx4. Run this script
Section titled “4. Run this script”Create a file called main.py:
import asynciofrom pathlib import Path
from deeptable import AsyncDeepTable
async def main(): client = AsyncDeepTable()
# Upload your spreadsheet file = await client.files.upload( file=Path("acme_subscriptions.xlsx") )
# Create a structured sheet (this triggers the conversion) structured_sheet = await client.structured_sheets.create(file_id=file.id)
# Wait for processing to complete while structured_sheet.status in ("queued", "in_progress"): await asyncio.sleep(10) structured_sheet = await client.structured_sheets.retrieve(structured_sheet.id)
# Download as a SQLite database sqlite = await client.structured_sheets.download(structured_sheet.id, format="sqlite") await sqlite.write_to_file("acme_subscriptions.sqlite")
if __name__ == "__main__": asyncio.run(main())Run it:
python main.pyCreate a file called main.ts:
import DeepTable from "@deeptable/deeptable";import * as fs from "fs";
const client = new DeepTable();
async function main() { // Upload your spreadsheet const file = await client.files.upload({ file: fs.createReadStream("acme_subscriptions.xlsx"), });
// Create a structured sheet (this triggers the conversion) let structuredSheet = await client.structuredSheets.create({ file_id: file.id, });
// Wait for processing to complete while (structuredSheet.status === "queued" || structuredSheet.status === "in_progress") { await new Promise((resolve) => setTimeout(resolve, 10000)); structuredSheet = await client.structuredSheets.retrieve(structuredSheet.id); }
if (structuredSheet.status === "failed") { throw new Error("Processing failed"); }
// Download as a SQLite database const response = await client.structuredSheets.download(structuredSheet.id, { format: "sqlite", }); const buffer = Buffer.from(await response.arrayBuffer()); fs.writeFileSync("acme_subscriptions.sqlite", buffer);}
main();Run it:
npx tsx main.tsWhat just happened?
Section titled “What just happened?”You uploaded a spreadsheet, and DeepTable:
- Analyzed the structure - finding tables, headers, and relationships
- Converted the messy spreadsheet data into clean, normalized tables
- Returned a SQLite database you or an LLM can query directly
Download as CSV or Parquet
Section titled “Download as CSV or Parquet”Need individual tables instead of a database? You can download each table separately:
async for table in client.structured_sheets.tables.list(structured_sheet.id): csv = await client.structured_sheets.tables.download( structured_sheet_id=structured_sheet.id, table_id=table.id, format="csv", # or "parquet" ) await csv.write_to_file(f"{table.name}.csv")for await (const table of client.structuredSheets.tables.list(structuredSheet.id)) { const response = await client.structuredSheets.tables.download( structuredSheet.id, table.id, { format: "csv" } // or "parquet" ); const buffer = Buffer.from(await response.arrayBuffer()); fs.writeFileSync(`${table.name}.csv`, buffer);}Next steps
Section titled “Next steps”- Explore the API Reference to see all available endpoints