Skip to content

Dependency declaration

A block declares on its class. Every export of the class runs with that one declaration.

from sdk import xratu

@xratu(["httpx>=0.27", "orjson>=3.10"], apt=["ca-certificates"], env={"PAGE_SIZE": "100", "LOG": "info"})
class Gateway:
    def list(self) -> list:
        ...

    def export(self) -> bytes:
        ...

How the example reaches the closure, the cell and the kernel

Gateway is one block, and it runs as one capsule, one resolved closure and one cell. Generation records its declaration once for the block:

{
  "dependency_intent": {
    "python": {"backend": "uv", "requirements": ["httpx>=0.27", "orjson>=3.10"]},
    "apt": ["ca-certificates"],
    "image": ""
  },
  "environment_declaration": {
    "LOG": "info",
    "PAGE_SIZE": "100"
  }
}
  1. The capsule carries that one dependency intent and one environment declaration for the whole block.
  2. The resolved closure has one dependency binding per entry: httpx, orjson and ca-certificates, each with requirement_scope: reusable_block.
  3. The cell mounts every selected component, and its module_ownership maps both httpx and orjson. list and export run in that same cell.
  4. The kernel dispatches a call to list or export by its export ordinal, inside that one cell. Both exports see the same environment values.

How the declaration shapes the cell

Every export of Gateway above inherits the class declaration:

flowchart TB
  S["gateway.py<br/>class: httpx, orjson, apt ca-certificates"]
  S --> L["list resolves<br/>httpx, orjson, apt ca-certificates"]
  S --> E["export resolves<br/>httpx, orjson, apt ca-certificates"]
  L --> U["Block set<br/>python: httpx, orjson<br/>apt: ca-certificates"]
  E --> U
  U --> C["One closure<br/>bindings python:httpx, python:orjson<br/>binding bundle:ca-certificates"]
  C --> Cell["One cell<br/>import view: httpx, orjson<br/>loader view: ca-certificates"]

The isolation boundary is the block, and the block is the source module: several classes in one module are still one block. An export that needs a dependency or a version the others must not see goes in its own module, which gives it its own closure and cell. See From code to cells for two blocks side by side, and Version coexistence.

One value per environment key across the block

A block is one source module, so several classes in one module form one block, with one capsule and one resolved runtime closure. They agree on the value for any given environment key, and two classes that declare different values for one key are refused at generation:

reusable capability block exports disagree on environment value PAGE_SIZE

To vary a value per export, pass it as an argument rather than declaring it.

Backend selection

The recorded backend is pip when pip=[...] appears and uv otherwise. The two are exclusive inside one declaration:

ValueError: xratu metadata must not mix pip with default/uv requirements

The backend is also one per block. Two classes in one module that declare uv and pip requirements give the block two backends, and generation refuses it:

one reusable capability block cannot mix uv and pip dependency declarations

Declared auth keys

Declared auth keys union across every callable in the block, because the process holding the bindings is the block's cell. See Secret binding declaration.

Related: Dependency and environment declaration covers the surface these rules apply to.