Guides
Load from Python and HTTP APIs
Turn any API, SaaS or custom source into tables with a Python function, and describe REST APIs that run entirely in Rust.
A Python function that fetches data becomes a table, declared with sl.source and
@source.table. Python tables take part in plan, apply and load with the same
write strategies, cursors and
contracts as any other table. They need the sqlload package
(Install); sqlload-cli doesn’t run them. Every function and setting is in the
Python API.
Setting up
Section titled “Setting up”List the folders holding your modules in sqlload.toml:
python_paths = ["sources"]default_target = "local"
[connections.warehouse]kind = "duckdb"database = "shop.duckdb"
[targets.local]connection = "warehouse"loader_schema = "raw"import sqlload as sl
shop = sl.source("shop", write_strategy="merge")
@shop.table(unique_key="order_id", cursor_column="updated_at")def orders(ctx: sl.Context): """Orders from the shop, one row per order.""" yield [ {"order_id": 1, "status": "paid", "total": 42.5, "updated_at": "2026-11-01T09:30:00Z"}, {"order_id": 2, "status": "placed", "total": 18.0, "updated_at": "2026-11-02T14:05:00Z"}, ]$ sqlload plan -v…└── raw.shop__orders merge (unique_key: order_id; NULLs in keys match) ├── source python sources/shop.py (shop)… ├── schema columns inferred on first load…$ sqlload load…created raw.shop__orders 6 columnsloaded raw.shop__orders 2 rows 0.0s…- A function runs only when its table loads, never when it is declared.
applydoesn’t create a Python table; its first load does. - The table is
{source}__{table}unless the source or table setstable_name. A@sl.tablewithout a source keeps its own name. Table names are unique across the project. - The description, the destination table’s comment, is
description=or else the docstring; both are optional.
See Declaring for every setting.
Describe the job, or yield the rows
Section titled “Describe the job, or yield the rows”| You have | Yield | Where the work happens |
|---|---|---|
A REST API that sl.http can describe |
An sl.http job |
Entirely in Rust: requests, pages, parsing, Arrow. No row crosses into Python. |
| JSON or NDJSON as bytes | sl.json(data) or sl.ndjson(data) |
The bytes cross once; parsing runs in Rust. |
| Arrow data: pyarrow, polars or pandas | The table, batch or DataFrame | It crosses as Arrow, keeping its types. |
| Rows built in Python, such as from an SDK | Dicts, or lists of dicts | SQLLoad types and converts every row. |
Pick the first row that fits. Yield your own rows when the source needs Python: an SDK, unusual authentication, or logic between requests.
HTTP APIs
Section titled “HTTP APIs”The connection holds the base URL, credentials and what every request shares:
[connections.shop]kind = "http"base_url = "https://api.example.com"token = "${ENV:SHOP_TOKEN}"auth = { kind = "bearer" }rate_limit = "10/s"max_in_flight = 4rate_limit, max_in_flight and retries (5 by default) hold across every table in one
sqlload load, but separate processes don’t share them, so load one API’s tables in one run. See
the http connection.
import sqlload as sl
shop = sl.source("shop", connection="shop", write_strategy="merge")api = sl.http(shop)
@shop.table(description="Orders, one row per order.", unique_key="order_id")def orders(ctx): return api.paginate( "/orders", paginator=sl.page_number("page"), select="$.items" )
@shop.table( description="Order lines.", unique_key=["order_id", "line_no"])def order_items(ctx): order_ids = api.paginate( "/orders", paginator=sl.page_number("page"), select="$.items[*].order_id", ) return api.fan_out( "/orders/{order_id}/items", over=order_ids, concurrency=8, select="$.items", on_status={404: "skip"}, )$ sqlload load…created raw.shop__orders 5 columnsloaded raw.shop__orders 5 rows 0.2screated raw.shop__order_items 5 columnsloaded raw.shop__order_items 10 rows 0.8s
✓ Completed 2 loaded, 15 rows, 0.9s…paginate reads every page of a path; fan_out requests a path once per key. Every paginator,
auth method and retry rule is under HTTP APIs.
Incremental requests
Section titled “Incremental requests”Pass ctx.cursor_value in params to ask only for what changed since the last load. Dates and
timestamps are sent as ISO 8601 text; a None parameter, as on the first run, is left out:
@shop.table( description="Orders, one row per order.", unique_key="order_id", cursor_column="updated_at", columns={"updated_at": "timestamp_tz"},)def orders(ctx): return api.paginate( "/orders", params={"updated_after": ctx.cursor_value}, paginator=sl.next_link("$.next"), select="$.items", )OAuth2
Section titled “OAuth2”For short-lived access tokens, give the connection a client_id, a client_secret and an OAuth2
auth. SQLLoad fetches the token and renews it before it expires:
[connections.erp]kind = "http"base_url = "https://api.example.com/v2"client_id = "loader"client_secret = "${ENV:ERP_CLIENT_SECRET}"auth.kind = "oauth2_client_credentials"auth.token_url = "https://auth.example.com/oauth/token"auth.scope = "accounts:read"For oauth2_refresh_token and where secrets go, see OAuth2.