Python client
A single-file client lives in
clients/python.
It uses only the standard library for HTTP, and pyarrow for Arrow results.
from curral import Client, CurralError
c = Client("https://curral.example.com", token="curral_...") # API key or OIDC ID token# c = Client("http://127.0.0.1:8080", user="analyst", password="...")
t = c.query("SELECT * FROM orders WHERE amount > $1", [100]) # pyarrow.Tabledf = t.to_pandas() # or polars.from_arrow(t)
for row in c.iter_rows("SELECT id, amount FROM orders"): # dicts, streamed as NDJSON ...
print(c.dry_run("DELETE FROM orders")) # decision, tables, targets, limits; nothing runsSemantic documents
Section titled “Semantic documents”On servers started with --docs-dir, the client reads, searches and writes
semantic documents:
notes = c.docs(table="orders", q="revenue") # list of dicts; headers_only=True skips bodieshits = c.search_docs("monthly revenue per customer")["results"] # best first: score, judged, doc
d = c.create_doc({"header": {"title": "Revenue"}, "context": {"body": "...", "tables": ["sales.main.orders"]}})d = c.patch_doc(d["id"], {"header": {"used_for": ["finance"]}}, if_match=d.etag) # merge patchd = c.update_doc(d["id"], {**c.doc(d["id"]), "context": {"body": "rewritten"}}) # full replacec.delete_doc(d["id"])doc(), create_doc(), update_doc() and patch_doc() return a Doc (a
dict) with an etag. Pass it as if_match= and a write over a newer version
fails with 412 instead of overwriting it.
Behavior
Section titled “Behavior”- Errors: a refused or failed request raises
CurralErrorwithstatusandrequest_id, the same id as in the audit log. - Row limit: when a result hits the server’s row limit, a
TruncatedResultWarningis issued. - Mid-stream failures raise an exception instead of returning a short result.
- Custom CA: pass
cafile=.
Without the client
Section titled “Without the client”Any Arrow-aware tool can read the stream directly:
import pyarrow as pa, requests
r = requests.post("http://127.0.0.1:8080/v1/query", auth=("analyst", "analyst-pw"), json={"sql": "SELECT * FROM orders", "format": "arrow"})table = pa.ipc.open_stream(r.content).read_all()With --flight-listen, ADBC’s Flight SQL driver reads the same data without
HTTP; see Database IDEs.