Skip to content

Unified clients for the Python SDK (phase 1) - #33

Merged
eunomie merged 52 commits into
dagger:mainfrom
eunomie:uc-phase1
Oct 7, 2026
Merged

eunomie merged 52 commits into
dagger:mainfrom
eunomie:uc-phase1

Conversation

@eunomie

@eunomie eunomie commented Sep 18, 2026 •

Copy link
Copy Markdown
Member

One generated client package per scope, used by a module and by a plain Python program alike. It replaces the per-dependency bindings and [[dependencies]]. Design: hack/designs/2026-09-15-unified-clients.md.

What a scope looks like

<scope>/pyproject.toml          uv workspace root, written by the SDK
<scope>/sdk/                    the SDK files (plus dagger_global/ while migrating)
<scope>/clients/core/           the generated core client
<scope>/clients/<name>/         one member per declared client

Each client is a PEP 420 namespace package under dagger_clients, loaded through Query.serveModule:

from dagger import function, object_type
from dagger_clients.lib import lib


@object_type
class Demo:
    @function
    async def hello(self, name: str) -> str:
        return await lib().greeting(name=name)

How a module runs

  • New modules run on a generated static Dang entrypoint ([entrypoint] source = "./sdk/entrypoint"), rendered into the scope. Existing modules keep their entrypoint kind on regenerate.
  • --remote-entrypoint uses the published shared entrypoint instead.
  • --legacy-runtime runs the module on this repository's runtime/. A module that sets include, exclude or its own source moves there on generate, because a v2 manifest cannot carry them.
  • The two flags refuse each other. A manifest naming both a runtime and an entrypoint is refused.
  • A Dang entrypoint is handed only the module source of each declared client, never the workspace. A probe check covers every route that could rebuild a directory (4,305 routes, nothing read) and has a negative control.
  • disableDefaultFunctionCaching and [codegen] are refused with a message instead of being ignored. cache= works on the generated entrypoint.

Migrating a module

Run from the workspace root, dependencies first, one module at a time:

  1. dagger module install <this SDK>
  2. dagger module migrate <path> -y
  3. dagger generate -y
  4. dagger functions -m <path>

dagger ws migrate only handles installed modules, so it reports "No migration needed" for a legacy module that is not installed. The README has the full flow. Tried on telchak/daggerverse: 13 of 18 modules migrate and run. The others use dagger.Env, removed from the core in v1.0.0-beta.10, or include of a sibling package.

Generation touches only what it made

Generation writes into a directory the user also owns. The [tool.dagger] generated marker is read as TOML, never as text, and only client, core and runtime count. When a marker cannot be read, nothing is deleted or overwritten. The scope file is edited byte-preserving, so comments, table order and members survive. [tool.uv.workspace] members and [project] dependencies are parsed with tomllib in the SDK's pinned image, and manifests go through the sdk-helpers ModuleManifest builder (v1.0.6).

Engine requirements

Needs dagger/dagger#14489–#14494 (declared-client cache key, serveModule resolving a local path in the calling module's own tree, git commit in the module identity, call digest passed to the entrypoint, private git clients, span hiding). They are in main and not in v1.0.0-beta.15. On an engine without them a local client can resolve in the caller's tree, and a changed client target can serve a stale cached result.

Checks

Run locally, not yet green in CI. hack/e2e-floor.sh runs 39 end-to-end checks on the floor release v1.0.0-beta.14; hack/e2e-local.sh runs them on your engine. sdk has 540 pytest tests. Each fix carries an inversion (sdk/tests/invert.py: 53 of 54 confirmed; the one that is not already has a duplicated assertion).

Not in this PR

  • include for entrypoint modules. A v2 manifest has no include and the entrypoint sees only the module's own directory, so a sibling package such as ../_agent_base cannot be reached. Such modules stay on the runtime. Follow-up.
  • source other than .: the scope is written beside the manifest while the module builds from source, so the module cannot see sdk/. Documented in the README.
  • Release: the v1 tag of dagger.io/sdk/python/entrypoint and runtime must move to this branch after merge. Until then the published tag refuses this layout.
  • Phase 2: publish the SDK files, remove the sdk/ copy from the scope, and remove the global client after a deprecation period.

The first release that runs Dang entrypoints and serves serveModule.

Signed-off-by: Yves Brissaud <[email protected]>
The SDK files may import nothing generated, so module support selects
the few fields it needs by name, with the arguments the bindings send.

Signed-off-by: Yves Brissaud <[email protected]>
A generated client carries a descriptor, not a connection: its session
serves the target once, through serveModule, before the first query.

Signed-off-by: Yves Brissaud <[email protected]>
It keeps dag.container() and dagger.Container working while a module
migrates to the clients, behind a flag.

Signed-off-by: Yves Brissaud <[email protected]>
The package no longer imports the one-file bindings. dagger.dag is the
default Session, or the global client when one is generated.

Signed-off-by: Yves Brissaud <[email protected]>
A module marks itself first, so it never provisions one in its own
container.

Signed-off-by: Yves Brissaud <[email protected]>
The SDK owns only its entries in a scope's pyproject.toml; the rest is
the user's and must come back exactly as written.

Signed-off-by: Yves Brissaud <[email protected]>
A scope vendors nothing: the SDK files, core and each client are uv
workspace members, installed when the project depends on them. Its
pyproject.toml is the user's content, so the build reads it as TOML.

Signed-off-by: Yves Brissaud <[email protected]>
The workspace the engine hands over is the caller's. It holds the module
only when the module sits in it, not when it was loaded from git.

Signed-off-by: Yves Brissaud <[email protected]>
A client is generated inside the scope that uses it, as a workspace
member, so a module's manifest no longer lists its clients.

Signed-off-by: Yves Brissaud <[email protected]>
The floor runs entrypoints and follows one over a runtime, so the
[runtime] table this SDK wrote went unread, and its engineVersion misled.

Signed-off-by: Yves Brissaud <[email protected]>
The module's code runs in an exec with no module context, so it cannot
resolve a local client itself. An ID is a capability, and the module is
third-party code, so the workspace stays with the caller.

Signed-off-by: Yves Brissaud <[email protected]>
engine-e2e existed because released engines lacked serveModule. The floor
has it, so its checks join the suite, and a floor job asserts that release.

Signed-off-by: Yves Brissaud <[email protected]>
With lock off by default, a Git client loaded whatever its ref resolved
to at run time, not the commit dagger.lock selected for generation.

Signed-off-by: Yves Brissaud <[email protected]>
The engine now serves a module's local client from the module's own
tree, so every target loads through serveModule.

Signed-off-by: Yves Brissaud <[email protected]>
An entrypoint of the user's own no longer needs to hand clients over,
and the probe now tries the IDs module code can reach on its own.

Signed-off-by: Yves Brissaud <[email protected]>
strcase split digits and camel case, so module3 got src/module_3 while
uv_build and the runtime import module3.

Signed-off-by: Yves Brissaud <[email protected]>
eunomie added 19 commits October 5, 2026 12:41
A function body can change without changing what types.dang describes,
so an edit no longer forces `dagger generate`. A change that does alter
the described types is served only after generation, and `dagger
generate` in CI, which must leave no diff, is what catches it.

Signed-off-by: Yves Brissaud <[email protected]>
An entrypoint older than this layout refuses the module and says to run
`dagger generate`, which cannot write the bindings the layout dropped.
That text stays as it is: users reach the published copy, not this one.

Signed-off-by: Yves Brissaud <[email protected]>
A module runs on an entrypoint written into it, on the one this SDK
publishes, or on a runtime its manifest names; a boolean cannot say which.

Signed-off-by: Yves Brissaud <[email protected]>
A generated entrypoint refused `cache=` and the shared one declared it
without effect: the exec both start is cached on its own recipe, which the
engine's call digest now joins (dagger/dagger#14491).

Signed-off-by: Yves Brissaud <[email protected]>
The engine then loads a module's types without running Python, and no
setting decides it. A module that already names an entrypoint or a runtime
keeps it, since only its manifest says what runs it.

Signed-off-by: Yves Brissaud <[email protected]>
--remote-entrypoint names the entrypoint this SDK publishes instead of
generating one into the module: a new module names it, and a module that
carries one of its own moves onto it and loses the files. A module on a
runtime of its own keeps the runtime, with or without the flag.

Signed-off-by: Yves Brissaud <[email protected]>
An argument that takes any object by id is annotated with the base class of
every object, as a client's bindings are. The global client's own module
imported it from nowhere, so a module whose core has such a field failed to
import dagger_global at all: `NameError: name '_Type' is not defined`.

Signed-off-by: Yves Brissaud <[email protected]>
A module the builtin Python runtime ran has a global `dag` in its code and
may have no bindings of its own to go by: its manifest says what ran it,
either a pre-1.0 dagger.json or the `[runtime] source = "python"` that
`dagger module migrate` writes from one. The generation that converts such a
module turns the global client on and records the flag, as it already does
for a module whose vendored bindings say the same.

A scope file that sets the flag now decides on its own, true or false: a
module that says false keeps no global client, whatever its manifest says.

Signed-off-by: Yves Brissaud <[email protected]>
A client loads a module in the workspace with serveModule, which asks the
engine for a module by its manifest. A target that still has only a pre-1.0
dagger.json has none, so the call fails later, inside the user's code, with
the engine's own words. Refuse at generation instead, naming the target and
the command that converts it.

Signed-off-by: Yves Brissaud <[email protected]>
disableDefaultFunctionCaching and [codegen] reached a generated module in one
list of settings "an entrypoint manifest cannot carry", and a dagger.json
carrying either had it dropped without a word. Refuse each on its own, in
both manifests, with what to do instead: a function's own cache= for the
first, and nothing for the second, which no entrypoint reads.

Signed-off-by: Yves Brissaud <[email protected]>
A manifest that says which files the module is, or roots it somewhere other
than its own directory, says what no entrypoint can honour. Generation
refused such a module, so a migrated one had no way forward; keep it on the
runtime its manifest names instead, with the setting as written and no
entrypoint in front of it. A pre-1.0 dagger.json goes the same way, exclude
and all, which the conversion writes as a negated include.

An entrypoint beside those settings is still refused: the manifest names what
runs the module, and only one thing can.

Signed-off-by: Yves Brissaud <[email protected]>
It scaffolded the module of the layout before, with a container-echo example
and the vendored source a generated module no longer has. A new module gets
the generated entrypoint, which the template was refused on, so the template
has nowhere left to go.

Signed-off-by: Yves Brissaud <[email protected]>
The three answers a manifest can give, as a table, with what generation does
with each: the generated entrypoint a new module gets, an entrypoint served
from elsewhere, and a runtime. Then the migration order, which the refusals
now point at: convert a module with `dagger module migrate`, generate it,
dependencies before their callers, and the global client that keeps code
written against the layout before working until it moves.

Signed-off-by: Yves Brissaud <[email protected]>
`dagger module migrate` writes the version a pre-1.0 config declared into the
manifest it leaves behind, beside the builtin runtime. Generation read that
version as the view to generate against, so a module fresh from migration got
core as an older engine served it, while every client was read in the view the
engine serves now. A client then held another core than the scope, and the
generator refused the pair; a module without clients was written against a
core the session does not serve, and said nothing.

The view now comes from the runtime the manifest names: a module that keeps a
runtime of its own runs on the version it declares, and everything else — a
module on an entrypoint, and one this SDK takes over from the builtin runtime —
runs on the engine's own.

Found on a corpus of 18 pre-1.0 modules (github.com/telchak/daggerverse),
where it blocked every module that has a client.

Signed-off-by: Yves Brissaud <[email protected]>
Two cores in one scope were reported as digests and nothing else: "the core
digest X given for the client N is not that of its schema's core, Y", and "the
schemas hold two cores, X and Y" with no name at all. Both happen when one
module was read in another engine view, which the engineVersion a module
declares selects, and neither said so or what to do about it.

Signed-off-by: Yves Brissaud <[email protected]>
The engine's `dagger workspace migrate` migrates the workspace and the modules
it installs; a module of your own is a candidate it lists and skips, so it
answers "No migration needed" while every module is still pre-1.0. And
converting a module loads its dependencies, so a dependency must be generated,
not only converted, before the modules that call it are.

Both cost a corpus of 18 modules a full afternoon, so the README now gives the
two commands per module, in order, and says what each leaves behind.

Signed-off-by: Yves Brissaud <[email protected]>
A manifest that says `include`, `exclude`, or a `source` of its own keeps the
module on the runtime it names, and after migration that is the runtime built
into the engine, which reads the layout before this one. Generation writes this
layout into such a module all the same, so it generates and then fails to load,
with the builtin runtime asking for `sdk/src/dagger/client/gen.py`. Say so where
the migration steps are, with what the module needs instead.

Signed-off-by: Yves Brissaud <[email protected]>
A scope file may name a path dependency outside the scope: one package the
modules of a repository share, as `../_agent_base` is shared by four modules of
telchak/daggerverse. The lock ran in a container holding the scope alone, so uv
could not read that package, and `uv lock` failed with "Distribution not found
at: file:///_agent_base" — which took `dagger generate` for the whole workspace
with it, since one scope that cannot generate stops them all. The workspace now
goes in behind the scope when the scope file names such a path, and the lock's
inputs stay the scope alone for every scope that does not.

The helper reads those paths with its TOML parser, as it reads the rest of
pyproject.toml.

Signed-off-by: Yves Brissaud <[email protected]>
`dagger.Env` is gone from the beta.15 core, and the package answered "Core types
moved to dagger_clients.core: from dagger_clients.core import Env", which is not
where it is either. The global client names every type of the core it was
generated against, so a name it lacks is a name this engine's core lacks: say
that, and leave the move to the names that moved.

Five modules of telchak/daggerverse name `dagger.Env`, and that advice is the
first thing their authors read.

Signed-off-by: Yves Brissaud <[email protected]>
Writing `[runtime] source` needs ModuleManifest.withLegacyRuntime, public since
dagger/sdk-helpers#8, which v1.0.6 carries: its tag peels to 16e5bf2, the merge
of that pull request. The dependency names the tag, and dagger.lock records the
commit behind it in place of the entries of the pin it replaces.

A bare single-word runtime source is the name of a runtime built into the engine
there, so what this SDK writes for its own runtime is a module reference.

Signed-off-by: Yves Brissaud <[email protected]>
A module whose files are not its own directory alone cannot run on an
entrypoint: `include`, `exclude` and a `source` of its own are what only a
runtime honours. Such a module used to keep `[runtime] source = "python"`, the
runtime built into the engine, which reads the layout before this one and
refuses to build what generation writes — so it generated and then failed to
load. It now moves to the runtime this SDK publishes, which builds this layout,
on the version the generator reads core in rather than the one a pre-1.0 config
declared.

`--legacy-runtime` asks for that runtime for any module, as `--remote-entrypoint`
asks for the published entrypoint; set together they are refused, naming both.
An entrypoint a module carries goes with the move, since the engine follows an
entrypoint over a runtime.

A module reference is a legal `[runtime] source`: proven end to end on a module
with a sibling package under `include`, which runs on this repository's runtime
fetched by ref. The published `dagger.io/sdk/python/runtime@v1` resolves today
to a tag older than this layout; the e2e points at the working tree by relative
path for the same reason.

Signed-off-by: Yves Brissaud <[email protected]>
The playground took its CLI from the floor release's image whatever engine the
check ran on. A CLI older than the engine it reaches through nesting waits for
an answer that never comes, so every check that drives one hung for the thirty
minutes CI allows and was cancelled: nine of them, on every head of this branch.
The image is now the release of the engine running the check, which on the floor
job is the floor's, so that job proves the floor as it did before.

Proven both ways on v1.0.0-beta.15+6b6a6665: runtime-call-check times out after
420s with the floor's CLI in the playground and passes in a minute with the
engine's own.

Signed-off-by: Yves Brissaud <[email protected]>
Three checks spelled out `REF = "/<path>"` and `PIN = None`, which is what a
client is in a workspace on disk. CI loads the workspace from a ref, where the
same path is a Git client carrying the commit it resolved to, so the checks
failed on every head of this branch while the SDK was writing the right thing.
The expectation now comes from the ModuleSource the check hands in, so each
shape is asserted as strictly as before.

The refusal for a target that was never migrated is for a client the engine
serves out of the workspace, and `dagger module migrate <path>` is no answer for
one that comes from Git, so that check asserts the refusal where it applies and
its absence where it cannot.

Signed-off-by: Yves Brissaud <[email protected]>
Every Python scope here is an e2e fixture, and the checks generate them
themselves, from a workspace of their own. `dagger generate` at the root wrote
the whole SDK into each of the seven registered scopes instead, 459 files no one
commits, so python-sdk/generate/stale failed on every head of this branch.
`generate.skip` leaves them alone, and `dagger generate --no-apply` now reports
no changes.

The entrypoint's copy of runtime/build.dang is the generated file this
repository keeps, and shared-entrypoint-build-check is what catches its drift.

Signed-off-by: Yves Brissaud <[email protected]>
A module that calls a local client asks the engine to serve it from the tree
the module was loaded from; an engine without dagger/dagger#14490 looks in the
caller's workspace instead and answers "dir module source does not contain a
dagger config file". The check asserted its way into that wall on the floor
release and on the engine CI runs, where nothing in this SDK could have made
the call work.

The first call is now the probe: that answer, from the engine itself rather
than a version string, skips the rest and says so in the check's output, naming
the issue. Every other engine takes the assertions as they were, and the one
that fails for another reason still fails, now with its output in the message.

Signed-off-by: Yves Brissaud <[email protected]>
The engine generates every scope the workspace registers, and this repository
registered seven whose generated trees nobody commits: `dagger generate` wanted
to write 459 files, 198k lines of this SDK copied into the e2e fixtures, which
is what python-sdk/generate/stale reported on every head of this branch. A
workspace-level `generate.skip` hid the generator from the CLI and not from the
check that Dagger Cloud runs.

The config registers no scope now. The seven checks that look a module up, or
run the engine's generate over one, register the fixture they need on the
workspace they pass, which also says in each check which scope it is about.
Nothing else changes: the fixtures stay inputs, and the checks that hand
generateScope a workspace of their own never needed a scope at all.

Signed-off-by: Yves Brissaud <[email protected]>
@eunomie
eunomie merged commit 8506bf5 into dagger:main Oct 7, 2026
42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant