Skip to main content

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,asyncpg,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 or psycopg; the sqlalchemy extra installs neither driver), AsyncpgDatabase (an asyncpg pool) and PsycopgDatabase (a psycopg 3 async pool), under zero_server.server.adapters. Another driver plugs into ZQLDatabase as a DBConnection whose query takes $1 placeholders.
  • Validation. @define_query(Model) and @define_mutator(Model) parse args with a Pydantic model or TypeAdapter first; 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 real handleMutateRequest, handleQueryRequest, PushProcessor and 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.run and through tx.run against 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.py starts Postgres, two rocicorp/zero containers 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 from e2e/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 as false.

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.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for zero-server 0.0.2
File Size Uploaded Provenance Actions
zero_server-0.0.2.tar.gz 55.1 kB With provenance Details for zero_server-0.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for zero-server 0.0.2
File Interpreter ABI Platform Actions
zero_server-0.0.2-py3-none-any.whl Python 3 none any Details for zero_server-0.0.2-py3-none-any.whl

Total release size: 128.1 kB

Release files / zero_server-0.0.2.tar.gz

Download URL zero_server-0.0.2.tar.gz
Size 55.1 kB
Tags Source
SHA-256 checksum
How to use checksums
c121719d46b9e41d35cc5768b3563f80f7ab753dd851ccefdb651cb2af2cdc46
BLAKE2b-256 checksum
How to use checksums
8dc90c0ee302bf05df252cc7b67a2e7dae5347ffe24183e17a2d84cecb3a6b7e
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 log

Release files / zero_server-0.0.2-py3-none-any.whl

Download URL zero_server-0.0.2-py3-none-any.whl
Size 73.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ede5b68d8095e82e4632849daef8eb8b9178db8438b87fce4db6b6943562038c
BLAKE2b-256 checksum
How to use checksums
65bf612554469a493468fe03882f92c9bdf1732b1a9130db9f173c61cac8b33d
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 log

Security for zero-server 0.0.2

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.

Select from 2 files

Attestation for zero_server-0.0.2.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 log

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page