Skip to content

Quickstart

This gets you from zero to a working query in 2 minutes. You only need Python and a Deep Lake API token.

Prerequisites

pip install requests

Get your API token from deeplake.ai under your workspace settings.

Setup

import requests

API_URL = "https://api.deeplake.ai"
TOKEN = "YOUR_TOKEN"
WORKSPACE = "YOUR_WORKSPACE"

headers = {
    "Authorization": f"Bearer {TOKEN}",
    "Content-Type": "application/json",
}

1. Check the connection

res = requests.get(f"{API_URL}/health")
print(res.json())
# {"status": "ok"}

2. Create a table

Tables must be schema-qualified with your workspace name and use the USING deeplake engine:

TABLE = "my_first_table"

res = requests.post(
    f"{API_URL}/workspaces/{WORKSPACE}/tables/query",
    headers=headers,
    json={
        "query": f"""
            CREATE TABLE IF NOT EXISTS "{WORKSPACE}"."{TABLE}" (
                id SERIAL PRIMARY KEY,
                title TEXT,
                content TEXT,
                created_at TIMESTAMPTZ DEFAULT NOW()
            ) USING deeplake
        """
    },
)
print(res.status_code)  # 200

3. Insert some rows

rows = [
    ("Getting started", "Deep Lake unifies tables, files, and search."),
    ("Vector search", "Use the <#> operator for similarity queries."),
    ("Hybrid search", "Combine BM25 and vector for best results."),
]

for title, content in rows:
    requests.post(
        f"{API_URL}/workspaces/{WORKSPACE}/tables/query",
        headers=headers,
        json={
            "query": f"""
                INSERT INTO "{WORKSPACE}"."{TABLE}" (title, content)
                VALUES ('{title}', '{content}')
            """
        },
    )

Eventual consistency

After INSERT, data may take a few seconds to become visible in SELECT queries. This is normal behavior for Deep Lake tables.

4. Query your data

res = requests.post(
    f"{API_URL}/workspaces/{WORKSPACE}/tables/query",
    headers=headers,
    json={"query": f'SELECT * FROM "{WORKSPACE}"."{TABLE}" ORDER BY id'},
)
print(res.json())

That's it. You have a table with data you can query with SQL.

What's next