Python
Query a ZXCV database from server-side Python. You’ll end with a script that reads live data, then wire the same client into a FastAPI endpoint.
Create a project
In the dashboard click Start building, or run zxcv
from your terminal. Open Settings → API and copy your project ref and
anon key — access is enforced server-side by your
authorization rules.
Create a table
In the SQL editor, create a todos table with a couple of rows:
create table todos (
id bigint generated always as identity primary key,
title text not null,
is_complete boolean not null default false
);
insert into todos (title) values ('Read the docs'), ('Ship an app');Install the SDK
pip install zxcvInitialize the client
Read your keys from the environment rather than hard-coding them. Set them in
your shell (or a .env you load at startup):
ZXCV_PROJECT=acme-store
ZXCV_ANON_KEY=your-anon-keyCreate a shared client:
import os
from zxcv import create_client
zxcv = create_client(
project=os.environ["ZXCV_PROJECT"],
anon_key=os.environ["ZXCV_ANON_KEY"],
)Fetch and render
Query the table and print the rows. execute() returns data and error —
error is None on success:
from zxcv_client import zxcv
response = zxcv.table("todos").select("*").execute()
if response.error:
raise SystemExit(response.error)
for todo in response.data:
print(todo["id"], todo["title"])Run it:
python main.pyThe anon key is safe in server-side code too — the Data Gateway enforces your
.policy rules on every request, so a client can only read what its rules
allow.
Serve it from FastAPI
Import the same client and return the rows from an endpoint:
from fastapi import FastAPI, HTTPException
from zxcv_client import zxcv
app = FastAPI()
@app.get("/todos")
def list_todos():
response = zxcv.table("todos").select("*").order("id").execute()
if response.error:
raise HTTPException(status_code=500, detail=str(response.error))
return response.dataRun the dev server:
pip install "fastapi[standard]"
fastapi dev app.pyDeploy
Ship to the global edge from your terminal:
npm i -g zxcv
zxcv link acme-store
zxcv deploy --prodEvery push gets a preview URL; --prod promotes to your domain. See
Deploy for custom domains and canaries.
Next steps
- Auth — add sign-in and row-level security
- Realtime — live updates as rows change
- SDK reference · Database