Any Python library¶
A reusable capability block is ordinary Python. The code you already have, and the libraries it uses, go into a block unchanged: you declare the libraries on the class and import them as usual. The block pipeline produces the block's interface from its method signatures, so each method's parameters and result use types the interface can carry.
For example, a block that summarises invoices with pandas:
# invoices.py
import io
import pandas as pd
from sdk import xratu
@xratu(["pandas>=2.2,<3"])
class Invoices:
def totals_by_customer(self, csv_text: str) -> dict[str, int]:
frame = pd.read_csv(io.StringIO(csv_text))
totals = frame.groupby("customer")["amount"].sum()
return {str(name): int(total) for name, total in totals.items()}
What you declare¶
@xratu lists every third-party Python distribution the block imports, with the
version range it works with. A system library the block needs from
outside the foundation's exported baseline goes in apt=[...] on the same
decorator.
Generation records the declaration in the block's manifest, and you can read it back before anything runs:
{
"dependency_intent": {
"python": { "backend": "uv", "requirements": ["pandas>=2.2,<3"] },
"apt": [],
"image": ""
}
}
A project that uses the block resolves the declaration into exact bytes: a compatible component from the foundation or from the project's prepared set, or one built for this block's closure. The block's cell then imports that exact version. See Dependency and environment declaration and Presence versus import authority.
What the interface carries¶
Inside a method, the library's own types are yours to use. The method's parameters and result form the block's interface, which the pipeline records in XCI types in the block's XCI source: scalars, lists, maps, records, variants, and references to buffers, streams, artifacts and handles.
In the example, the DataFrame is built and discarded inside the call, and the method returns a map of customer names to totals. A caller in another block, on another pandas version or with no pandas at all, receives that map.
When a library value is the result itself, it takes the interface form that fits it: a table as a columnar buffer, an array as a tensor buffer, and a live object, such as a loaded model or an open client, as a resource the caller holds a handle to. See Block boundary.
Several libraries, several versions¶
Each block declares and resolves its own libraries, so blocks in one workflow may use libraries that cannot be installed together, including two versions of the same one. See Version coexistence.
Next: Library opacity covers what the kernel knows about the libraries a block uses.