zero-server
A community Python server SDK for Zero. It is not affiliated with or endorsed by Rocicorp.
It ports what @rocicorp/zero/server gives a TypeScript backend: the query endpoint (ZERO_QUERY_URL), the mutate endpoint (ZERO_MUTATE_URL), the ZQL query builder, defineQueries and defineMutators, and tx.mutate and tx.run on Postgres. The client and zero-cache stay in TypeScript, and a Python backend serves the same TypeScript client a TypeScript backend would.
Compatibility is pinned to one Zero release at a time. This version is tested against @rocicorp/zero 1.10.0 (see ZERO_VERSION).
Usage
pip install "zero-server[sqlalchemy,starlette]" # or [asyncpg], or [psycopg]
The schema stays in your TypeScript schema.ts, because the client needs it. Emit it as JSON, and generate Python types from it:
// emit-schema.ts
import {schema} from './schema.ts';
process.stdout.write(JSON.stringify(schema));
node emit-schema.ts > schema.json
zero-server codegen schema.json -o zero_schema.py
zero_schema.py has a TypedDict per table for a row, an insert, an update and a key, and a builder and tx.mutate typed by them. A server then looks like this:
from pathlib import Path
from pydantic import BaseModel
from sqlalchemy.ext.asyncio import create_async_engine
from starlette.applications import Starlette
from zero_schema import Project, create_builder, mutate
from zero_server import ApplicationError, define_mutator, define_mutators, define_queries, define_query, load_schema
from zero_server.integrations.starlette import zero_routes
from zero_server.server.adapters.sqlalchemy import SQLAlchemyDatabase
schema = load_schema(Path("schema.json"))
zql = create_builder(schema)
db = SQLAlchemyDatabase(create_async_engine("postgresql+asyncpg://..."), schema)
@define_query
def my_projects(*, args, ctx):
return zql.project.where("ownerID", ctx["userID"]).related("tasks").order_by("name", "asc")
class NewTask(BaseModel):
id: str
projectID: str
title: str
@define_mutator(NewTask)
async def create_task(*, tx, ctx, args: NewTask):
project: Project | None = await tx.run(zql.project.where("id", args.projectID).one())
if project is None or project["ownerID"] != ctx["userID"]:
raise ApplicationError("Not your project")
await mutate(tx).task.insert({"id": args.id, "projectID": args.projectID, "title": args.title})
app = Starlette(
routes=zero_routes(
schema=schema,
database=db,
queries=define_queries({"projects": {"mine": my_projects}}),
mutators=define_mutators({"task": {"create": create_task}}),
authenticate=verify_token, # your function: request -> user ID, or None when logged out
)
)
Point ZERO_QUERY_URL and ZERO_MUTATE_URL at /query and /mutate. With FastAPI, app.router.routes.extend(zero_routes(...)). With another framework, call handle_query_request and handle_mutate_request yourself; zero_server/integrations/starlette.py is short enough to copy.
- Databases.
SQLAlchemyDatabase(SQLAlchemy's asyncio engine on asyncpg),AsyncpgDatabase(an asyncpg pool) andPsycopgDatabase(a psycopg 3 async pool), underzero_server.server.adapters. Another driver plugs intoZQLDatabaseas aDBConnectionwhosequerytakes$1placeholders. - Validation.
@define_query(Model)and@define_mutator(Model)parse args with a Pydantic model orTypeAdapterfirst; a failure reaches the client as upstream's validation error. - Strict building.
create_builder(schema, strict=True)refuses an unknown column when the query is built. Upstream only refuses it when the endpoint maps the query, failing the whole batch, so this is for your tests.
How compatibility is checked
The published npm package is the definition of correct. Every test diffs Python against it:
- Wire.
harness/runs the realhandleMutateRequest,handleQueryRequest,PushProcessorand the query builder under Node. Hypothesis generates pushes (with duplicates, gaps, refusals and cleanup mutations) and builder programs, sends each through both sides against identical Postgres databases, and diffs the responses and every row written. - SQL. The same generated queries run through upstream's
ZQLDatabase.runand throughtx.runagainst one seeded database, and the result rows are compared, never the SQL text.
The wire and SQL tiers run against every adapter.
- End to end.
e2e/run.pystarts Postgres, tworocicorp/zerocontainers at the pinned version, the TypeScript reference app server and the Python one. An unmodified Zero client runs the same script through each, and the run fails if the client ends up with different data, the databases differ, or the reference run strays frome2e/expected.json.
Run them with uv run pytest (needs Node 24 and Docker, or ZERO_SERVER_PG pointing at a Postgres) and uv run --group e2e python e2e/run.py.
Known differences
- Parse errors. When a request is malformed, the message after
Failed to parse push body:describes the bad field in Pydantic's words, not valita's. The rest of the response matches, and zero-cache only logs it. - Non-string values against text columns. Upstream passes such a value to the JavaScript driver as is, so the driver decides how it binds. zero-server binds
String(value), which is what postgres.js does except for an array whose first element is a boolean, which it binds asfalse.
License
Apache-2.0. Zero itself is Apache-2.0, and code ported from rocicorp/mono keeps its notices.
Metadata
Release files for zero-server 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| zero_server-0.0.1.tar.gz | 54.4 kB | With provenance | Details for zero_server-0.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| zero_server-0.0.1-py3-none-any.whl | Python 3 | none | any | Details for zero_server-0.0.1-py3-none-any.whl |
Total release size: 126.9 kB
Release files / zero_server-0.0.1.tar.gz
| Download URL | zero_server-0.0.1.tar.gz |
|---|---|
| Size | 54.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8f2587daf89545eca814debd3fcb20f9691d7940b1417f86e0efc1b46c791fff
|
|
BLAKE2b-256 checksum How to use checksums |
2d8c1846491b47afcc0f634275cc506949cecfb947713ff8356e063fea6cc7c2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 15, 2026.
Transparency logRelease files / zero_server-0.0.1-py3-none-any.whl
| Download URL | zero_server-0.0.1-py3-none-any.whl |
|---|---|
| Size | 72.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d784644f77648beb47d78add86bb05e25d0b4af8c4a1bd7f0bb1d609be77b3e9
|
|
BLAKE2b-256 checksum How to use checksums |
2bdc579ff362aced07737e5ed6e9513270de84daf6a273f59aa087450e5f6af7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 15, 2026.
Transparency logSecurity for zero-server 0.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for zero_server-0.0.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 15, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.