Load a CSV, TSV, JSON or Parquet file into a table from the SQL page, a link, curl or Python.
Load a file into a new table, or append its rows to a table you already have. Files can be uploaded from your computer, fetched from a link, or sent from code. Every import writes as you, through the same roles, data policies and query history as SQL you run yourself.
| Formats | CSV, TSV and other delimited text, JSON (an array or one object per line) and Parquet |
| Compression | gzip (.gz) for text formats |
| Size | Up to 100 MB per file |
| Columns | Up to 1,000 |
| Where tables go | The default schema of a Contrast database. Connected catalogs are read-only. |
Contrast detects the format, delimiter, header row and each column's type from the file. Column types are string, bigint, double, boolean, date and timestamp. Column names are lowercased, with other characters replaced by underscores.
Rows are checked and loaded into a staging table first, so the target table changes only when every row has loaded. A failed import leaves it as it was. You can close the dialog while an import runs. History in the same dialog lists your imports with their row counts and, for failures, the reason, such as a value that doesn't fit its column's type.
Code authenticates with a personal access token that has the write scope. Connect on the SQL page, under Write, shows these examples with your workspace and database filled in.
Send the file as the request body, and name the target with query parameters:
cat events.csv | curl -sS -X POST \
"https://api.contrastdb.com/v1/workspaces/$WORKSPACE_ID/warehouse/file-imports?database=contrast&table=events&file_name=events.csv" \
-H "Authorization: Bearer $CONTRAST_API_TOKEN" \
-H "Content-Type: application/octet-stream" \
--data-binary @-| Parameter | Meaning |
|---|---|
database | The database to load into |
table | The table name: a lowercase letter, then lowercase letters, numbers and underscores |
mode | create (the default) makes a new table and fails if it exists; append adds rows to an existing one |
file_name | Optional. Its extension helps detect the format |
format, delimiter, header | Optional. Override what is detected |
The response is the import, with status queued. The load runs in the background; poll GET .../warehouse/file-imports/{id} until status is succeeded or failed. A failed import has error_code and error_message. GET .../warehouse/file-imports lists your recent imports.
To load from a link instead, send JSON:
curl -sS -X POST "https://api.contrastdb.com/v1/workspaces/$WORKSPACE_ID/warehouse/file-imports" \
-H "Authorization: Bearer $CONTRAST_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{"database": "contrast", "table": "events", "mode": "append", "url": "https://example.com/events.csv.gz"}'The JSON body also takes columns, a list of {"source_name", "name", "type", "skip"} overrides. Without url, the import waits for the file at PUT .../file-imports/{id}/file, which lets you set overrides before uploading. POST .../file-imports/preview returns the detected columns and the first rows without loading anything.
Batch rows in memory and send them as one file. Each batch loads all at once or not at all.
import csv, io, os, time
import requests
API = f"https://api.contrastdb.com/v1/workspaces/{os.environ['WORKSPACE_ID']}/warehouse/file-imports"
HEADERS = {"Authorization": f"Bearer {os.environ['CONTRAST_API_TOKEN']}"}
rows = [
{"id": 1, "name": "Ada", "signed_up": "2026-01-05"},
{"id": 2, "name": "Grace", "signed_up": "2026-02-11"},
]
batch = io.StringIO()
writer = csv.DictWriter(batch, fieldnames=rows[0].keys())
writer.writeheader()
writer.writerows(rows)
response = requests.post(API, headers=HEADERS, data=batch.getvalue().encode(), params={
"database": "contrast", "table": "users", "mode": "create", "file_name": "users.csv",
})
response.raise_for_status()
job = response.json()
while job["status"] not in ("succeeded", "failed"):
time.sleep(2)
job = requests.get(f"{API}/{job['id']}", headers=HEADERS).json()
print(job["status"], job["rows_loaded"], job["error_message"])To keep a pandas DataFrame's types, send it as Parquet: write it with df.to_parquet(buffer) and pass file_name="users.parquet". Use mode=append for later batches.
Small writes can also go through the query API as CREATE TABLE, INSERT ... VALUES, INSERT ... SELECT or CREATE TABLE ... AS SELECT. The Postgres endpoint is read-only.